您的位置:首页 > 数据库 > MySQL

数据库----(MySQL基本常见sql)

2016-09-18 12:10 369 查看
删除唯一索引:

alter table T_PARTY_REG drop index UK_T_PARTY_REG_REG_CODE;

新建索引:

create index IX_T_PARTY_REG_REG_CODE on DBUSER.T_PARTY_REG

(

REG_CODE

);

修改列属性定义:

alter table T_PARTY_REG modify LOGIN_PWD VARCHAR(50) comment ‘登录密码’;

修改列名:

alter table T_PARTY_REG change COM_ID TENANT_ID INT(5) comment ‘租户ID’;

表重命名:

alter table ENT_BASEINFO rename T_ENT;

表增加列至指定行后面:

alter table DBUSER.T_PARTY_REG add SIGNATURE VARCHAR(200) comment ‘签名’ after ACCOUNT_STATUS;

说明:第一行为:alter table t1 add column addr varchar(20) not null first;

表删除列:

alter table dbuser.D_BANK_HEAD drop column PIC_URL;

表删除主键:

Alter table t_order_log drop primary key;

alter table DBUSER.T_PARTY_LOGIN_HISTORY drop foreign key FK_Reference_6;

表增加主键:

Alter table T_PDT_EXTEND add primary key(PDT_ID);

查看表存在的约束:

select * from INFORMATION_SCHEMA.TABLE_CONSTRAINTS where table_name = ‘t_ent’;

删除外键约束:

alter table DBUSER.T_PARTY_LOGIN_HISTORY drop foreign key FK_Reference_6;

alter table DBUSER.T_PARTY_LOGIN_HISTORY drop key FK_Reference_6;

修改主键自增:

mysql> alter table tb1 change id id int not null primary key auto_increment; –存在主键无法设置自增

ERROR 1068 (42000): Multiple primary key defined

mysql> Alter table tb1 drop primary key;

Query OK, 10 rows affected (0.20 sec)

Records: 10 Duplicates: 0 Warnings: 0

mysql> alter table tb1 change id id int not null primary key auto_increment;

Query OK, 10 rows affected (0.19 sec)

Records: 10 Duplicates: 0 Warnings: 0

更改表字段备注信息:

update information_schema.columns t set t.column_comment = ‘注释’

where t.table_schema=’数据库名’

and t.table_name=’表名’

and t.column_name=’列名’;

删除自增:

Alter table tb1 change id id int;

修改表引擎方法

alter table table_name engine=innodb;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: