alter table a add constraint fk_a_to_b foreign key(col) references b(col)
create table a (customname varchar(20) primary key clustered ,address varchar(100)) create table b (cname varchar(20),num int FOREIGN KEY (cname) REFERENCES a(customname) )
create table a (customname varchar(20) primary key clustered ,address varchar(100)) create table b (cname varchar(20),num int FOREIGN KEY (cname) REFERENCES a(customname) )
Create database cat go use cat go CREATE TABLE s(s# int not null primary key,s_name varchar(8) not null) go CREATE TABLE c (c# int not null primary key,c_name varchar(8) not null) go CREATE TABLE cs(c# int not null,s# int not null,cj tinyint not null default(0), primary key (c#,s#),foreign key(s#) references s(s#),foreign key(c#) references c(c#)) go
create table a
(customname varchar(20) primary key clustered ,address varchar(100))
create table b
(cname varchar(20),num int
FOREIGN KEY (cname) REFERENCES a(customname)
)
create table a
(customname varchar(20) primary key clustered ,address varchar(100))
create table b
(cname varchar(20),num int
FOREIGN KEY (cname) REFERENCES a(customname)
)
go
use cat
go
CREATE TABLE s(s# int not null primary key,s_name varchar(8) not null)
go
CREATE TABLE c (c# int not null primary key,c_name varchar(8) not null)
go
CREATE TABLE cs(c# int not null,s# int not null,cj tinyint not null default(0),
primary key (c#,s#),foreign key(s#) references s(s#),foreign key(c#) references c(c#))
go