admin 管理员组文章数量: 1184232
2024年4月17日发(作者:it高级培训)
sql语句学习
数据定义语言(DDL):
1)创建数据库(create):create database database-name;
eg. create database test;
2)删除数据库:drop database dbname;
database test;
3)创建新表:create table tabname(col1 type1 [not null] [primary key],col2
type2 [not null],..);
eg.根据已有的表创建新表的例子:create table tab_new like tab_old;create
table tab_new as select col1,col2… from tab_old definition only;
4)删除表:drop table tabname;
5)增加列:alter table tabname add column col type;
6)添加主键: alter table tabname add primary key(col) ;
7)删除主键:alter table tabname drop primary key(col) ;
8)创建索引:create [unique] index idxname on tabname(col….) ;
9)删除索引:drop index idxname; 注:索引是不可更改的,想更改必须删除重
新建;
10)创建视图:create view viewname as select statement;
2. 数据操纵语言(DML)
1)查询语句(select)
eg1. select * from table1 where field1 like '%value1%';
eg2. select * from table1 order by field1,field2 [desc];
eg3. select count as totalcount from table1;
eg4. select sum(field1) as sumvalue from table1;
eg5. select avg(field1) as avgvalue from table1;
eg6. select max(field1) as maxvalue from table1;
eg7. select min(field1) as minvalue from table1;
eg8. select a.a, a.b, a.c, b.c, b.d, b.f from a LEFT OUT JOIN b ON a.a = b.c;(注:
版权声明:本文标题:sql语句学习_经典大全_推荐 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1713343826a630009.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论