当前位置: 代码迷 >> MySQL >> mysql 惯用 sql 语句(一)
  详细解决方案

mysql 惯用 sql 语句(一)

热度:387   发布时间:2016-05-05 17:08:16.0
mysql 常用 sql 语句(一)
【1】清空表语句

truncate table fke_message;


【2】重设自增字段起始值
alter table fke_message auto_increment = 10001;



【3】常用建表语句

DROP TABLE IF EXISTS `fke_message`;CREATE TABLE `fke_message` (  `id` int(10) NOT NULL AUTO_INCREMENT,  `username` varchar(40) NOT NULL DEFAULT '' COMMENT '用户名',  `tel` varchar(20) NOT NULL DEFAULT '' COMMENT '电话号码',  `email` varchar(40) NOT NULL DEFAULT '' COMMENT '电子邮箱',  `msginfo` varchar(255) NOT NULL DEFAULT '' COMMENT '留言信息',  `createdate` int(11) NOT NULL DEFAULT '0' COMMENT '时间戳',  PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;



【4】常用查询语句

1. 统计用户量

select count(distinct id) from fke_member


2. 增加字段

alter table e_down add soft_version1 varchar(50) NOT NULL default '' ;


3. 修改字段类型

alter table address modify column city varchar(50) NOT NULL default '';


4. 添加索引

alter table member add index id_index(id);


【5】数据库创建语句

create database test default CHARACTER SET utf8 COLLATE utf8_general_ci;



  相关解决方案