mysql常用sql语句(一)

2015-11-21 01:37:55 · 作者: · 浏览: 2
【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;