-
foreign key
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
Last edited by magical01; 10-26-2003 at 12:01 PM.
-
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
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|