mysql常用语句操作
删除某个字段:
ALTER TABLE `tableName` drop COLUMN `columeName`;
增加某个字段:
ALTER TABLE `tableName` ADD COLUMN `columeName` varchar(255) NOT NULL DEFAULT '' COMMENT '备注信息' AFTER `anotherColumeName`;
修改字段属性
ALTER TABLE
`tableName`
MODIFY email VARCHAR(200) NOT NULL DEFAULT 'a@a.com';
添加PRIMARY KEY(主键索引)
ALTER TABLE `table_name` ADD PRIMARY KEY ( `column` )
添加UNIQUE(唯一索引)
ALTER TABLE `table_name` ADD UNIQUE ( `column` )
添加INDEX(普通索引)
ALTER TABLE `table_name` ADD INDEX index_name ( `column` )
添加FULLTEXT(全文索引)
ALTER TABLE `table_name` ADD FULLTEXT ( `column`)
添加多列索引
ALTER TABLE `table_name` ADD INDEX index_name ( `column1`, `column2`, `column3` )
创建表:
CREATE TABLE `tableName` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`msg` varchar(60) NOT NULL DEFAULT '' COMMENT '备注',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='导出excel';
删除数据库
drop database tableName;
删除表
drop table 表名;
随机访问5条记录
SELECT * FROM tableName ORDER BY RAND() LIMIT 5;