在SQL SEVER 2000中 关系都是拖出来的吗?
可以用TRANSACT-SQL 语句来创建表与表之间的关系吗???

解决方案 »

  1.   

    alter table a add constraint fk_a_to_b foreign key(col) references b(col)
      

  2.   


    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)
    )
      

  3.   


    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)
    )
      

  4.   

    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