sql查询语句大全及实例(查询数据表的sql语句)

   日期:2022-02-23     文章发布:文章发布    网络转载:生活号    
核心提示:1.查询外键信息 select*fromINFORMATION_SCHEMA.KEY_COLUMN_USAGEwhereREFERENCED_TABLE_NAME='t_sys_application' 2.查找所有表的语句 selecttable_namefrominformation_schema.tableswheretable_schema='当前数据库'; 1.修改表名 renameta...
移动站源标题:http://mip.818114.com/news/item-175412.html

1.查询外键信息

select * from INFORMATION_SCHEMA.KEY_COLUMN_USAGE where REFERENCED_TABLE_NAME=’t_sys_application’

2.查找所有表的语句

select table_name from information_schema.tables where table_schema=’当前数据库’;

1.修改表名

rename table test to test1;

alter table test_a rename to sys_app;

2.修改表注释

alter table sys_application comment ‘系统信息表’;

二:修改字段信息

1.修改字段类型和注释

alter table sys_application modify column app_name varchar(20) COMMENT ‘应用的名称’;

2.修改字段类型

alter table sys_application modify column app_name text;

3.单独修改字段注释

目前没发现有单独修改字段注释的命令语句。

4.设置字段允许为空

alter table sys_application modify column description varchar(255) null COMMENT ‘应用描述’;

5.增加一个字段,设好数据类型,且不为空,添加注释

alter table sys_application add `url` varchar(255) not null comment ‘应用访问地址’;

6.增加主键

alter table t_app add aid int(5) not null ,add primary key (aid);

7.增加自增主键

alter table t_app add aid int(5) not null auto_increment ,add primary key (aid);

8.修改为自增主键

alter table t_app modify column aid int(5) auto_increment ;

9.修改字段名字(要重新指定该字段的类型)

alter table t_app change name app_name varchar(20) not null;

10.删除字段

alter table t_app drop aid;

11.在某个字段后增加字段

alter table `t_app` add column gateway_id int not null default 0 AFTER `aid`; #(在哪个字段后面添加)

12.调整字段顺序

alter table t_app change gateway_id gateway_id int not null after aid ; #(注意gateway_id出现了2次)

免责声明:本网部分文章和信息来源于互联网,本网转载出于传递更多信息和学习之目的,并不意味着赞同其观点或证实其内容的真实性,如有侵权请通知我们删除!(留言删除
 
 
更多>同类行业

同类新闻
最新资讯
最新发布
最受欢迎
网站首页  |  黄页  |  联系方式  |  信息  |  版权隐私  |  网站地图  |  API推送  |  网站留言  |  RSS订阅  |  违规举报  |  京ICP备2000095号