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
 General SQL Server Forums
 New to SQL Server Programming
 How to test a foreign key constraint?

Author  Topic 

vegan
Starting Member

1 Post

Posted - 2011-12-02 : 21:44:27
IBM dbms wont let me run code keeps saying the table in use - its for my assignment. i need to run this code and then i have to test the foreign key constraint. how do i test it and what error msg it supposed to produce? heres the code im trying to run,


ALTER TABLE SCHEMA20.CUSTOMER
ADD CONSTRAINT SCHEMA20.CUSTOMER_CC_FK
FOREIGN KEY (COUNTRY_CODE)
REFERENCES SCHEMA20.COUNTRY (COUNTRY_CODE);

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-03 : 00:16:13
once you create the foreign key constraint, inserting any value in COUNTRY_CODE column of SCHEMA20.CUSTOMER which is not a valid value present in SCHEMA20.COUNTRY.COUNTRY_CODE table should throw a foreign key violation error if its created correctly.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -