[英]creating table with primary key and 2 foreign keys with error
I'm trying to create a table that has a composite PK constraint using Rep_ID, Store_ID, and Quarter and I'm trying to create a FK constraint on Rep_ID and Store_ID 我正在尝试使用Rep_ID,Store_ID和Quarter创建具有复合PK约束的表,并且正在尝试在Rep_ID和Store_ID上创建FK约束
This is my statement: 这是我的声明:
CREATE TABLE REP_CONTRACTS( Store_ID INT(8), Name INT(5), Quarter CHAR(3), Rep_ID INT(5), PRIMARY KEY (Rep_ID, Store_ID, Quarter), Rep_ID INT REFERENCES BOOK_STORES(Rep_ID), Store_ID INT REFERENCES BOOK_STORES(Store_ID) );
These are my tables: 这些是我的表:
Book Stores: 书店:
Column Name Datatype Constraint Comments Store_ID INT(8) PRIMARY KEY column Name VARCHAR(30) Should be UNIQUE and NOT NULL Contact VARCHAR(20) Rep_ID INT(5)
Rep Contracts 销售合同
Column Name DataType Store_ID INT(8) Name INT(5) Quarter CHAR(3) Rep_ID INT(5)
I have already created the book store table, I'm trying to create the rep contracts table 我已经创建了书店表,我正在尝试创建销售代表合同表
I also get the error Duplicate column name 'Rep_ID'. Add a differentiating column alias.
我也收到错误
Duplicate column name 'Rep_ID'. Add a differentiating column alias.
Duplicate column name 'Rep_ID'. Add a differentiating column alias.
when running this query 运行此查询时
you are declaring REPID twice in the table, which is why you are getting the duplication error. 您在表中两次声明了REPID,这就是为什么您收到重复错误的原因。 You may also want to create the column "Store ID" before using it in the Primary Key Statement.
您可能还需要在“主键语句”中使用“ Store ID”列之前将其创建。
CREATE TABLE REP_CONTRACTS(
Store_ID INT(8),
Name INT(5),
Quarter CHAR(3),
Rep_ID INT(5) REFERENCES BOOK_STORES(Rep_ID),
Store_ID INT REFERENCES BOOK_STORES(Store_ID),
PRIMARY KEY (Rep_ID, Store_ID, Quarter)
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.