前言:
眼前我们对“删除唯一约束sql语句”都比较讲究,同学们都想要分析一些“删除唯一约束sql语句”的相关知识。那么小编同时在网络上汇集了一些对于“删除唯一约束sql语句””的相关内容,希望小伙伴们能喜欢,看官们一起来学习一下吧!数据库中共有五种约束,分别是主键约束(Primay Key Coustraint)、外键约束(Foreign Key Counstraint)、唯一约束(Unique Counstraint)、检查约束(Check Counstraint)、默认约束(Default Counstraint)。
主键约束(Primay Key Coustraint)
1)建表时直接添加:CREATE TABLE student(stu_id INT(10) PRIMARY KEY);
联合主键:CREATE TABLE student(stu_id INT(10),stu_name VARCHAR(30),CONSTRAINT PK_ID_NAME PRIMARY KEY(user_id,user_name));
2)通过ALTER语句
ALTER TABLE student MODIFY user_id INT(10) PRIMARY KEY;
ALTER TABLE student ADD PRIMARY KEY(stu_id );
ALTER TABLE student ADD CONSTRAINT PK_ID PRIMARY KEY(stu_id );
删除主键约束:ALTER TABLE student DROP PRIMARY KEY;
默认约束(Default Counstraint)
1)在创建表的时候添加:CREATE TABLE t_user(stu_id INT(10) DEFAULT 3);
2)通过ALTER语句添加
ALTER TABLE student MODIFY stu_id INT(10) DEFAULT 2;
ALTER TABLE student CHANGE stu_id stu_id INT(10) DEFAULT 2;
删除默认约束
ALTER TABLE student MODIFY stu_id INT(10);
ALTER TABLE student CHANGE stu_id stu_id INT(10);
唯一约束(Unique Counstraint)
1)创建表时添加:CREATE TABLE t_user(user_id INT(10) UNIQUE);
CREATE TABLE student (stu_id INT(10),UNIQUE KEY(stu_id ));
2)通过ALTER语句
ALTER TABLE student MODIFY stu_id INT(10) UNIQUE;
ALTER TABLE student CHANGE stu_id stu_id INT(10) UNIQUE;
ALTER TABLE student ADD UNIQUE(stu_id );
ALTER TABLE student ADD UNIQUE KEY(stu_id );
ALTER TABLE student ADD CONSTRAINT UN_ID UNIQUE(stu_id );
ALTER TABLE student ADD CONSTRAINT UN_ID UNIQUE KEY(stu_id );
删除唯一约束:ALTER TABLE student DROP INDEX stu_id ;
检查约束(Check Counstraint)
CREATE TABLE student(
stu_id INT(6) AUTO_INCREMENT PRIMARY KEY,
stu_name VARCHAR(30) NOT NULL UNIQUE,
CHECK(stu_id >0)
);
标签: #删除唯一约束sql语句