MySQL常用操作语句
来源:互联网 发布:北京软件开发公司 编辑:程序博客网 时间:2024/04/30 10:46
查看innodb下的ddl语句错误信息
SHOW ENGINE INNODB STATUS
查看见表语句
show create table [table name]
增加主键,主键可以是一列,也可以是多列组合,但一个表中只能有一个主键。
alter table [tablename] add constraint [constrain name] primary key ([column1]{column2,...})
增加外键
alter table[tablename] add constraint [constraint name] foreign key([column]) reference [anthoer tablename][column]
删除主键约束
alter table[table name] drop contraint [constraint name]
修改列属性
alter table [table name] modify([ column][字段类型][是否为空])
添加字段: alter table `user_movement_log` 删除字段: alter table `user_movement_log` drop column Gatewayid 调整字段顺序: ALTER TABLE `user_movement_log` CHANGE `GatewayId` `GatewayId` int not null default 0 AFTER RegionID //主键 alter table tabelname add new_field_id int(5) unsigned default 0 not null auto_increment ,add primary key (new_field_id);//增加一个新列 alter table t2 add d timestamp; alter table t2 drop column c;//重命名列 alter table t1 change a b integer; alter table t1 change b b bigint not null; alter table t1 rename t2;加索引 mysql> alter table tablename change depno depno int(5) not null; mysql> alter table tablename add primary key(id);加唯一限制条件的索引 mysql> alter table tablename add unique emp_name2(cardnumber);删除某个索引 mysql>alter table tablename drop index emp_name;修改表: 增加字段: mysql> ALTER TABLE table_name ADD field_name field_type;修改原字段名称及类型: mysql> ALTER TABLE table_name CHANGE old_field_name new_field_name field_type;删除字段: mysql> ALTER TABLE table_name DROP field_name;
Add column GatewayId int not null default 0 AFTER `Regionid` (在哪个字段后面添加)
alter table infos add ex tinyint not null default ‘0′;//删除列
//改变列的类型
alter table infos change list list tinyint not null default ‘0′;
//重命名表
mysql> alter table tablename add index 索引名 (字段名1[,字段名2 …]);
mysql> alter table tablename add index emp_name (name);加主关键字的索引
1、创建表格时添加: create table table1(id int auto_increment primary key,…) 2、创建表格后添加: alter table table1 add id int auto_increment primary key 自增字段,一定要设置为primary key. 附:mysql 中的alter table mysql> alter table employee change depno depno int(5) not null; 加索引 mysql> alter table 表名 add index 索引名 (字段名1[,字段名2 …]); 例子: mysql> alter table employee add index emp_name (name); 加主关键字的索引 mysql> alter table 表名 add primary key (字段名); 例子: mysql> alter table employee add primary key(id); 加唯一限制条件的索引 mysql> alter table 表名 add unique 索引名 (字段名); 例子: mysql> alter table employee add unique emp_name2(cardnumber); 查看某个表的索引 mysql> show index from 表名; 例子: mysql> show index from employee; 删除某个索引 mysql> alter table 表名 drop index 索引名; 例子: mysql>alter table employee drop index emp_name; 修改表:增加字段:mysql> ALTER TABLE table_name ADD field_name field_type; 查看表:mysql> SELECT * FROM table_name; 修改原字段名称及类型:mysql> ALTER TABLE table_name CHANGE old_field_name new_field_name field_type; 删除字段:ALTER TABLE table_name DROP field_name
- MySQL常用操作语句
- MySQL常用操作语句
- Mysql常用操作语句
- MySQL常用操作语句
- mysql 常用操作语句
- mysql常用操作语句
- MySql 常用操作语句
- Mysql常用数据库操作语句
- MYSQL基本操作常用语句
- 常用的mysql操作语句
- Mysql数据库 常用操作语句
- 常用Mysql数据库操作语句
- php操作mysql的常用语句详解
- MySql 的一些常用操作语句
- 常用的Mysql数据库操作语句大全
- MySQL数据库常用操作语句大全
- 常用Mysql字符串操作语句记录
- 常用的Mysql数据库操作语句大全
- 在eclipse中生成英文的javadoc(转自:http://zyp731.javaeye.com/blog/98432)
- 关于重启系统服务
- 数据库方面常见面试题
- 关于FormView在编辑模板下找不到控件的问题
- 求助 SUM 和ROUP BY 的使用方法。感激不尽~!!![
- MySQL常用操作语句
- 系统引导管理器GRUB
- MySql 的unique key 与 primary key
- magento -- 正式发布网银在线Motopay信用卡站内支付收款模块
- A herf="#" 的问题
- 什么是“跨进程 API Hook”?
- JDBC工具类(ConDB、Dao、MyProperties、MyException、db属性文件)
- 右值引用
- 看网络商城如何赢得消费者青睐