create DATABASE aaa;
use aaa;
SELECT DATABASE ();
#复合约束
create table user1(
id int,
`name` char(10),
`password` char(25),
CONSTRAINT uk_user_name_pwd UNIQUE(`name`,`password`)
);
CREATE TABLE USER(
id INT,
`name` VARCHAR(15),
`password` VARCHAR(25),
CONSTRAINT uk_user_name_pwd UNIQUE (`name`,`password`)
)
select * from user;
INSERT into user
VALUES(1,'tom','abc');
INSERT into user
VALUES(1,'tom111','abc');
desc user;
select * from information_schema.table_constraints
where table_name="user"
ALTER TABLE user
DROP INDEX uk_user_name_pwd ;
CREATE TABLE test(
last_name VARCHAR(15),
salary INT,
email VARCHAR(25)
);
desc test;
CREATE TABLE test5(
id INT,
last_name VARCHAR(15),
salary INT,
email VARCHAR(25),
CONSTRAINT pk_test5_id PRIMARY KEY(id)
);
select * from information_schema.table_constraints
where table_name="test5";
INSERT INTO test5(id,last_name,salary,email)
VALUES(1,'Tom1',4000,'tom@126.com');
SELECT*from test5;
INSERT INTO test5(id,last_name,salary,email)
VALUES(2,'Tom1',4000,'tom@126.com');
CREATE TABLE test8(
id INT,
last_name VARCHAR(15),
salary INT,
email VARCHAR(25),
PRIMARY KEY(last_name,salary)
);
desc test8;
INSERT INTO test8(id,last_name,salary,email)
VALUES(1,'Tom1',4000,'tom@126.com');
SELECT*from test8;
CREATE TABLE test9(
id INT,
last_name VARCHAR(15),
salary INT,
email VARCHAR(25)
);
desc test9;
SELECT*from test9;
ALTER TABLE test9
ADD PRIMARY KEY (id);
ALTER TABLE test9
drop PRIMARY KEY ;