为了账号安全,请及时绑定邮箱和手机立即绑定

mysql 删除约束 的SQL语句!

mysql 删除约束 的SQL语句!

一只斗牛犬 2019-04-14 15:08:06
mysql 删除约束 的SQL语句!
查看完整描述

2 回答

?
PIPIONE

TA贡献1829条经验 获得超9个赞

alter table语句:

完整用法:
ALTER [IGNORE] TABLE tbl_name

alter_specification [, alter_specification] ...

alter_specification:

table_option ...
ADD [COLUMNcolumn_definition [FIRST | AFTER col_name ]
ADD [COLUMN] (column_definition,...)
ADD {INDEX|KEY} [index_name] [index_type] (index_col_name,...)
| ADD [CONSTRAINT [symbol]]

PRIMARY KEY [index_type] (index_col_name,...)
| ADD [CONSTRAINT [symbol]]

UNIQUE [INDEX|KEY] [index_name] [index_type] (index_col_name,...)
| ADD [FULLTEXT|SPATIAL] [INDEX|KEY] [index_name] (index_col_name,...)
| ADD [CONSTRAINT [symbol]]

FOREIGN KEY [index_name] (index_col_name,...)

[reference_definition]
| ALTER [COLUMN] col_name {SET DEFAULT literal | DROP DEFAULT}
CHANGE [COLUMN] old_col_name column_definition

[FIRST|AFTER col_name]
| MODIFY [COLUMN] column_definition [FIRST | AFTER col_name]
| DROP [COLUMN] col_name
| DROP PRIMARY KEY
| DROP {INDEX|KEY} index_name
| DROP FOREIGN KEY fk_symbol
| DISABLE KEYS
| ENABLE KEYS
| RENAME [TO] new_tbl_name
| ORDER BY col_name [, col_name] ...
| CONVERT TO CHARACTER SET charset_name [COLLATE collation_name]
| [DEFAULT] CHARACTER SET charset_name [COLLATE collation_name]
| DISCARD TABLESPACE
| IMPORT TABLESPACE

index_col_name:

col_name [(length)] [ASC | DESC]

index_type:

USING {BTREE | HASH}

删除 主键 和外键约束:

ALTER TABLE mytablename
DROP PRIMARY KEY
DROP FOREIGN KEY fk_symbol;

还有就是怎么样查询 约束;

你可以通过查看该表的 创建语句来 查看 约束:

SHOW CREATE TABLE mytablename;

得到ddl语句;



查看完整回答
反对 回复 2019-04-15
  • 2 回答
  • 0 关注
  • 4528 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信