这两天打算写一些关于SQL方面和SQL优化的基础。自己要坚持啊!
常用的SQL语句:
1.创建数据库:
create database dbname;
2.删除数据库:
drop database dbname;
3.创建新表:
create table tname(col1 type1 [not null] [primary key],col2 type2 [not null],..)
4.删除新表:
drop table tname;
5.创建索引:
create index indexname on tname(col...);
6.删除索引:
drop index indexname;
7.创建视图:
create view viewname as select statement;
8.删除视图:
drop view viewname;
9.基本的语句:
选择:select * from student; where col=...
插入: insert into tname(field1,field2) value(value1,value2);
更新:update tname set field1=value1 where
删除:delete from tname where name='daming';
排序:select * from tname order by field1,field2 [desc]
总数:select count as totalcount from tname
求和:select sum(field1) as sumvalue from table1
平均:select avg(field1) as avgvalue from tname
最大:select max(field1) as maxvalue from tname
最小:select min(field1) as minvalue from tname
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/24760053/viewspace-696387/ ,如需转载,请注明出处,否则将追究法律责任。