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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 check

Author  Topic 

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2009-11-05 : 05:54:17
Hi,
Table1 has fields such as ID, field1, field2, field3, etc.

Table2 has fields such as ID, FieldName

How is it possible to have a check so that everytime a new record is added to Table2.FieldName it has to be one of the fields in Table1 i.e. field1 or field2 or field3, etc.? so Table2.FieldName only accepts one of the field names in Table1.
Can I have this check built on creating Table2 ?

Thanks

yosiasz
Master Smack Fu Yak Hacker

1635 Posts

Posted - 2009-11-05 : 10:54:01
yes you can do that by adding a CHECK Constraint on that field. if you read up on that it will help you figure out what you need

<><><><><><><><><><><><><><><><><><><><><><><><><>
If you don't have the passion to help people, you have no passion
Go to Top of Page

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2009-11-05 : 11:01:28
Created a check constraint on the table.
Thank you
Go to Top of Page
   

- Advertisement -