i have already created the table, and named the primary key for it. how would i go back and add a foreign key.
thanks
magcutie08@yahoo.com
Printable View
i have already created the table, and named the primary key for it. how would i go back and add a foreign key.
thanks
magcutie08@yahoo.com
create table x (id int constraint x_pk primary key nonclustered, name char(10), deptid int)
create table y (id int constraint y_pk primary key nonclustered, deptname char(10))
alter table x add constraint x_y_fk foreign key (deptid) references y([id])
where did you get the x_y_fk foreign key part from is it just the names of the tables?
it is the name of the constraint. if you are not giving system will create the name automatically
got it to work thanks