SQL练习

 1 # 创建数据库
 2 1 create database database-name
 3 # 删除数据库
 4 drop database dbname
 5 # 备份SQL server
 6 创建 备份数据的device
 7 use master
 8 exec sp_addumpdevice 'disk','testback','c:mssql7backupMyNwind_1.dat'
 9 开始备份
10 backup database pubs to testback
11 # 创建新表
12 create table tabname
13 # 删除新表
14 drop table tabname
15 # 增加一个列
16 alter table tabname add column col type
17 # 添加主键
18 alter table tabname add primary key(col)
19 # 创建索引
20 create [unique] index idxname on tabname
21 # 几个简单的基本的SQL语句
22 选择: 
23 select * from table where 范围
24 插入:
25 insert into table(field,field) values (values,values)
26 # 删除:
27 delete from table where 范围
28 # 更新
29 update table set field1=values where 范围
30 # 查找
31 select * from table where field like '%values%'
32 # 排序
33 select * from table order by field, field [desc]
34 # 总数
35 select count as totalcount from table
36 # 求和
37 select sum(field) as sumvalue from table
38 # 平均
39 select avg(field) as avgvalue from table
40 # 最大
41 select max(field) as maxvalue from table
42 # 最小
43 select min(field) as minvalue from table
1 limit 和 offset 用法
2 select * from test limit 3 offset 1
3 当 limit和offset组合使用的时候,limit后面只能有一个参数,表示要取的的数量,offset表示要跳过的数量 。
原文地址:https://www.cnblogs.com/miss103/p/13574035.html