常用的SQL汇总

/**mysql 取得数据库名*/
show databases

/**根据库名取得表名*/
SELECT TABLE_NAME from information_schema.`TABLES` where TABLE_SCHEMA = 'dashboard';

/**根据表名取得字段名*/
select COLUMN_NAME from information_schema.COLUMNS where table_name = 'da_dashboard_si_test';

/**根据表名取得表结构信息*/
show full columns from da_dashboard_si_test

/**删除表*/
DROP TABLE IF EXISTS 表名

/**添加字段*/
alter table 表名 add(score int not null);

/**移除字段*/
alter table 表名 drop column score;

/**变更字段*/
alter table 表名 change name score int not null;

/**并查询*/
(select id from 表1 )union(select id from 表2);

/**创建普通索引*/
create index 索引名 on 表名 (字段);

/**创建唯一索引*/
create unique index 索引名 on 表名 (key字段);

/**移除索引*/
drop index 索引名 on 表名;

猜你喜欢

转载自blog.csdn.net/zhenzhen823/article/details/81318327