SQL SEVER 的基本请求指令

SQL分类:DDL--数据定义语言(create,alter,drop,declare)

     DML--数据操纵语言(select,delete,update,insert)

                  DCL--数据控制语言(grant,revoke,commit,rollback)

基本语句:

      1、创建数据库:create database 数据库名字

      2、删除数据库:drop database 数据库名字

      3、创建新表:create table 表名……

      4、删除新表:drop table 表名

      5、增加一个列:alter table 表名 add column col type

      6、添加主键:alter table 表名 add primary key(col)

      7、删除主键:alter table 表名 drop primary key(col)

      8、创建索引:create [unique] index idxname 表名(col……)

      9、删除索引:drop index idxname

      10、创建视图:create view viewname as select statement

      11、删除视图:drop view viewname

      12、选择:select  *from 表名 where 条件范围

      13、插入:insert into 表名(表1,表2) values(值1,值2)

      14、删除:delect  from 表名 where 范围

      15、更新:update 表名 set 想更改的名字=更改值 where 范围

      16、查找:select *from 表名 where 范围

      17、排序:select *from 表名 order by field1,field2 [desc]

      18、总数:select count *as sumvalue from 表名

      19、求和:select sum(field1)as sumvalue from 表名

      20、平均值:select avg(field1)as avgvalue from 表名

      21、最大值:select max(field1)as maxvalue from 表名

      22、最小值:select min(field1)as  minvalue from 表名

      23、复制表:select * into b from a where 范围

      24、拷贝表:insert into b select d,e,f from b

      25、跨数据库拷贝:insert into b(a,b,c) select d,e,f from b in 具体数据库名 where 范围条件

      26、子查询:select a,b,c from a where a in(1,2,3)

      27、显示文章、提交人和最后的回复时间:select a.title,a.username,b.addaate from table a,(select max(adddate) adddate from table where table.title=a.title) b

      28、外连接查询:select  a.a,a.b,a.c,b.c,b.d,b.f from a LEFT OUT JOIN b ON a.a = b.c

      29、select *from(select a,b,c FROM a) T where t.a>1

      30、随机选择记录:select newid()

      31、随机取出10条数据:select top *from 表名 order by newid()

      32、(select a from tableA) except (select a from tableB) except (select a from tableC)

      33、查询前10条记录:select top 10 *from table1 where范围

      34、数据库分页:select top 10 b *from(select top 20)

posted @ 2018-08-01 20:13  嗨_放飞梦想  阅读(232)  评论(0编辑  收藏  举报