数据库----(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;
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;
相关文章推荐
- MySql的基本用法(2)_常见的数据库操作
- 常见数据库Oracle,sqlserver,mysql字段类型与java.sql.Types的对应
- oracle mysql sqlserver 查看当前所有数据库及数据库基本操作命令
- 【sql入门】根据要求绘制E/R图,创建数据库(2)mySQL建表基本语法及主键外键选择
- ios开发-数据库网络之mysql创建数据库,表,基本SQL语句(5)
- 数据库基本----SQL语句大全
- 常见数据库分页SQL语句[转]
- Oracle/Sqlserver/MySQL三种数据库选取第m至第n行记录(zt)
- Mysql关于数据库和表的几个最基本命令
- 常见数据库分页SQL语句
- [数据库测试]强烈推荐一个python ODBC数据源插件,可支持Oracle,Db2,Mysql,Sql-server以及各种数据库版本,附例子和测试程序
- 数据库MySQL的基本操作命令
- 用sql语句取出mysql 数据库中表的字段的说明信息
- Mysql关于数据库和表的几个最基本命令
- [转] 在 MySQL 数据库中使用 C 执行 SQL语句
- mysql导出数据库表的创建sql语句(使用mysql control center/MYSQL-Front)
- 数据库常见十大错误No4--SQL语句
- 数据库sql操作基本命令集锦
- [转] 在 MySQL 数据库中使用 C 执行 SQL语句
- 精讲MySQL 数据库的 SQL 语法参考