图书借阅系统中,用户想实现向数据表“借阅”中添加主键,该如何操作( ).
A: alter table 借阅 add constraint pk_b primary key(学号)
B: alter table 借阅 add constraint pk_b primary key(书号)
C: alter table 借阅 add constraint pk_b primary key(学号,书号)
D: alter table 借阅 add constraint pk_b unique(学号,书号)
A: alter table 借阅 add constraint pk_b primary key(学号)
B: alter table 借阅 add constraint pk_b primary key(书号)
C: alter table 借阅 add constraint pk_b primary key(学号,书号)
D: alter table 借阅 add constraint pk_b unique(学号,书号)
举一反三
- 【单选题】图书借阅系统中,用户想实现向已经创建好的“借阅表”中添加主键“借阅编号”,该如何操作?( ) A: alter table 借阅表 add constraint fk_b foreign key(借阅编号) B: alter table 借阅表 modify primary key(借阅编号); C: alter table 借阅表 add primary key(借阅编号); D: alter table 借阅表 add unique(借阅编号)
- 为表TEST中ID列添加主键约束的语法是() A: ALTER TABLE TEST CHANGE( ID INT PRIMARY KEY) B: ALTER TABLE TEST ADD( ID INT PRIMARY KEY) C: ALTER TABLE TEST MODIFY( ID INT PRIMARY KEY) D: ALTER TABLE TEST ADD CONSTRAINT PK PRIMARY KEY (ID)
- 为salerecord表CID字段添加外键,引用client表中CID字段。 A: ALTER TABLE salerecord ADD CONSTRAINT fk1 FOREIGN KEY(CID) REFERENCES client(CID); B: ALTER TABLE salerecord ADD CONSTRAINT pk1 PRIMARY KEY(CID) REFERENCES client(CID); C: ALTER TABLE salerecord ADD CONSTRAINT fk1 FOREIGN KEY(CID) REFERENCES client(CID),ADD CONSTRAINT pk2 PRIMARY KEY(GID) REFERENCES goods(GID); D: ALTER TABLE salerecord ADD CONSTRAINT pk1 PRIMARY KEY(CID) REFERENCES client(CID),ADD CONSTRAINT pk2 PRIMARY KEY(GID) REFERENCES goods(GID);
- 假设需要为表 customer 添加主键约束,主键列为 customer_id,可以使用如下( )方式。 A: Alter table CUSTOMER ADD pk_customer primary key (customer_id); B: Altertable CUSTOMER ADD constraint pk_customer primary key (customer_id); C: Alter table CUSTOMER ADD constraint pk_customer (customer_id); D: Alter table CUSTOMER ADD primary key (customer_id);
- 为salerecord表GID字段添加外键,引用goods表中GID字段。 A: ALTER TABLE salerecord ADD CONSTRAINT pk2 PRIMARY KEY(GID) REFERENCES goods(GID); B: ALTER TABLE salerecord ADD CONSTRAINT fk2 FOREIGN KEY(GID) REFERENCES goods(GID); C: ALTER TABLE salerecord ADD CONSTRAINT fk2 FOREIGN KEY(CID) REFERENCES goods(CID); D: ALTER TABLE salerecord ADD CONSTRAINT pk2 PRIMARY KEY(CID) REFERENCES goods(CID);