2013-04-01 20 views
0
Create table test1 
(
    id bigint Not Null, 
    name varchar(10) Not Null 
    constraint pk_test primary key(id,name) 
) 
Create table test2 
(
    Mid bigint Not Null references test1(id) , 
    MSalary varchar(10) Not Null 
) 

在test2中,我无法创建对test1 id的引用请帮助我..如何从给定的详细信息中创建参考密钥

回答

0

你需要一个外键来引用一个表。试试这个:

CREATE TABLE test1 
(
    id bigint NOT NULL PRIMARY KEY, 
    name varchat(10) NOT NULL 
) 

CREATE TABLE test2 
(
    Mid bigint NOT NULL, 
    MSalary varchar(10) NOT NULL, 
    FOREIGN KEY (Mid) REFERENCES test1(id) 
) 
+0

感谢Trickery对我的问题感兴趣,但实际上我需要表test1中的复合键。它怎么可能..它给错误.... – social