Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
tsures77
Starting Member
1 Post |
Posted - 2011-01-22 : 09:27:11
|
| hi all !have a newbe question about constrains.using sql 2000.i have 2 tables: customer and customerTypes.customer table has the follwing columns :1. CustomerID int pk2. CustomerName varchar3.CuatomerLastName varchar4.CustomerType intcustomerTypes table has the follwing columns :1.TypeID int pk2.TypeName varchar3.TypeValue intnow ...i want that in column customer.CustomerType the values can only come from customerTypes.TypeValue where customerTypes.TypeName equals "regular".shoul i use constarins or just forigen key ?thanks in advancehubby |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2011-01-22 : 09:48:20
|
A Foreign Key is a constraint. And that is the type of constraint you want.ALTER TABLE customerADD CONSTRAINT FK_Customer_CustomerType Foreign Key (CustomerType) References CustomerTypes (TypeID);GO |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-01-24 : 10:41:02
|
| if you want to enforce that where condition also you need to implement this in a trigger or use CHECK constraint utilizing a UDF where you check this.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|