龙空技术网

mysql查找约束的sql语句

重庆思庄 55

前言:

今天姐妹们对“mysql中的检查约束”可能比较关怀,各位老铁们都想要分析一些“mysql中的检查约束”的相关文章。那么小编也在网上汇集了一些对于“mysql中的检查约束””的相关内容,希望大家能喜欢,同学们快快来学习一下吧!

比如:sztech下面的一张表emp,查它有几个约束 :

mysql> use sztech

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

Database changed

mysql> show create table emp\G

*************************** 1. row ***************************

Table: emp

Create Table: CREATE TABLE `emp` (

`empid` int(11) NOT NULL DEFAULT '0',

`last_name` varchar(20) DEFAULT NULL,

`salary` double DEFAULT NULL,

`hire_date` date DEFAULT NULL,

PRIMARY KEY (`empid`),

KEY `idx_emp_empid` (`empid`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8

1 row in set (0.00 sec)

mysql> alter table emp add primary key (empid);

mysql> select CONSTRAINT_SCHEMA, CONSTRAINT_NAME,TABLE_NAME,CONSTRAINT_TYPE from information_schema.TABLE_CONSTRAINTS where TABLE_NAME='emp';

+-------------------+-----------------+------------+-----------------+

| CONSTRAINT_SCHEMA | CONSTRAINT_NAME | TABLE_NAME | CONSTRAINT_TYPE |

+-------------------+-----------------+------------+-----------------+

| sztech | PRIMARY | emp | PRIMARY KEY |

+-------------------+-----------------+------------+-----------------+

1 row in set (0.00 sec)

标签: #mysql中的检查约束