COMMIT WORK
;
DROP DATABASE IF EXISTS Campaign_Database;
CREATE DATABASE Campaign_Database;
USE Campaign_Database;
DROP TABLE IF EXISTS CONTRIBUTOR
;
DROP TABLE IF EXISTS CAMPAIGN
;
DROP TABLE IF EXISTS PLEDGE
;
CREATE TABLE CONTRIBUTOR
( CONTRIBUTOR_ID VARCHAR(50) primary key,
Address char(50) not null,
City char(50) not null,
State char(2) not null,
Zip INTEGER(6) not null,
Home_Phone char (15)
)ENGINE = InnoDB;
;
CREATE TABLE CAMPAIGN
( CAMPAIGN_ID VARCHAR(50) primary key,
Chair_First_Name char (50) not null,
Chair_Last_Name char (50) not null,
Launch_Date char (11) not null,
End_Date char (11) not null,
Fundraising_Goal INTEGER NOT NULL
)ENGINE = InnoDB;
;
CREATE table PLEDGE
(
FOREIGN KEY (CONTRIBUTOR_ID) REFERENCES CONTRIBUTOR (CONTRIBUTOR_ID),
FOREIGN KEY (CAMPAIGN_ID) REFERENCES CAMPAIGN (CAMPAIGN_ID),
Date_Pledged char(11) not null primary key,
Amount INTEGER NOT NULL,
PAID char(1) not null
CHECK (PAID in ('Y','N')),
Payment_Date char(11)
)ENGINE = InnoDB;
;
COMMIT WORK
;
这个当前是我用于决赛任务的mysql编码。 我已经尝试了几种方法,但没有成功地在“承诺”中创建两个外键。表
如果我至少可以知道出了什么问题,我将不胜感激。谢谢。
答案 0 :(得分:0)
您需要CONTRIBUTOR_ID
表格中的CAMPAIGN_ID
,PLEDGE
字段。
CREATE table PLEDGE
(
CONTRIBUTOR_ID VARCHAR(50),
CAMPAIGN_ID VARCHAR(50),
FOREIGN KEY (CONTRIBUTOR_ID) REFERENCES CONTRIBUTOR (CONTRIBUTOR_ID),
FOREIGN KEY (CAMPAIGN_ID) REFERENCES CAMPAIGN (CAMPAIGN_ID),
Date_Pledged char(11) not null primary key,
Amount INTEGER NOT NULL,
PAID char(1) not null
CHECK (PAID in ('Y','N')),
Payment_Date char(11)
)ENGINE = InnoDB;
;
在本声明中
FOREIGN KEY (CONTRIBUTOR_ID) REFERENCES CONTRIBUTOR (CONTRIBUTOR_ID),
第一个CONTRIBUTOR_ID
是指定义约束的表,第二个是指它所指向的表。