2024年4月2日发(作者:)
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;(注:


发布评论