create table score(
cscore int(11),
st_id int(50) references student(id),
cs_id int(30) references classes(id),
primary key(st_id,cs_id)
);
create table score(
cscore int(11),
st_id int(50),
cs_id int(30),
primary key(st_id,cs_id),
FOREIGN KEY (st_id) REFERENCES student(id),
FOREIGN KEY (cs_id) REFERENCES classes(id)
);
create table score(
cscore int(11),
st_id int(50),
cs_id int(30),
primary key(st_id,cs_id),
CONSTRAINT `FK_ID_ST` FOREIGN KEY (st_id) REFERENCES student(id),
CONSTRAINT `FK_ID_CS` FOREIGN KEY (cs_id) REFERENCES classes(id)
);
alter table 表名 add constraint FK_ID foreign key(你的外键字段名) REFERENCES 外表表名(对应的表的主键字段名);
CREATE TABLE tb
(
id INT IDENTITY(1,1) PRIMARY KEY,
name VARCHAR(20)
);
*CREATE TABLE table_test(
id INT NOT NULL,
name VARCHAR(20) NOT NULL,
address VARCHAR(20),
PRIMARY KEY(id)
);
CREATE TABLE table_test(
user_id INT NOT NULL,
user_name VARCHAR(20) NOT NULL,
user_address VARCHAR(20),
PRIMARY KEY (user_id, user_name)
);
alter table 表名 add primary key(字段列表)
?
ALTER TABLE Employees
ADD CONSTRAINT PK_EmployeesID PRIMARY KEY (EmployeeID)
ALTER TABLE (表名) ADD id INT(16) NOT NULL
PRIMARY KEY AUTO_INCREMENT FIRST;
alter table(表名) modify id integer auto_increment
alter (表名) DROP PRIMARY KEY