I know, it sounds easy.. but MSFT doesn't have any specific scripts for adding a foreign key to a table. You have to sift through BOL (Books online) and they refer you to the alter table statements. Long story short. Here is how to add Foreign Key To SQL Server table.
alter table [table Name] WITH CHECK
add constraint [fk_name] FOREIGN KEY ([column]) references [Reference table Name] ([column referenced])
in other words.. Here is how I did it.
alter table customer WITH CHECK
add constraint FK_Custid FOREIGN KEY (customer_type_id) references customer_type(id)
Wednesday, October 24, 2007
Subscribe to:
Posts (Atom)