为表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)
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)
举一反三
- 假设需要为表 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);
- 图书借阅系统中,用户想实现向数据表“借阅”中添加主键,该如何操作( ). 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: create table t1(id number primary key,name varchar2(10)) B: create table t1(id number constraint p_k primary key(id),name varchar2(10)) C: create table t1(id number constraint p_k primary key,name varchar2(10)) D: create table t1(id number,name varchar2(10),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);
- 【单选题】图书借阅系统中,用户想实现向已经创建好的“借阅表”中添加主键“借阅编号”,该如何操作?( ) 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(借阅编号)