Insert Into 数据表名称(字段名称1,字段名称2,...) values(字段值1,字段值2,...)
insert into user(username,password,age) values('李老四','6666',45)
Update 数据表名称 Set 字段名称=字段值,字段名称=字段值,...[Where 条件]
Delete from 数据表
下列查询返回在LONDON(伦敦)或SEATTLE(西雅图)的所有雇员:
SELECT * from employees WHERE UPPER(city) IN ('LONDON','SEATTLE')
下面示例利用DATEDIFF函数,确定在 pubs 数据库中标题发布日期和当前日期间的天数。
SELECT DATEDIFF(day, OrderDate, getdate()) AS no_of_days from table1
返回字符串"wonderful"在 titles 表的 notes 列中开始的位置。
SELECT CHARINDEX('wonderful', notes)
以下是返回的结果:(第47个字符位置)
显示工作站的名称:select host_name() as [Client Computer Name]
下例是检索 titles 表中百分之五十的书。如果 titles 表中包含了 18 行,则将检索前 9 行。
SELECT TOP 50 PERCENT title from titles
字段名称 [Not] Between 起始值 and 终止值
列出BOOK表中30至50元的书
select * from book where price between 30 and 50
字段名称 [Not] In(列出值1,列出值2,...)
从BOOK表中列出价格为30,40,50,60的所有书
select * from book where price in(30,40,50,60)
字段名称 [Not] Like "通配符"
列出BOOK表中出版社含电的所有记录
select * from book where publishing like '*电*'
列出BOOK表中出版社第一个字是电的所有记录
select * from book where publishing like '电*'
---
select Sum/Count/Avg/Max/Min(字段名称) [As 新名称] from 数据表名称
sum求和:
求出总价格做为合计字段
select sum(price ) as 合计 from book
count统计数量:
统计BOOK表中有多少条记录做为数量字段
select count(id) as 数量 from book
AVG平均:
算出BOOK表中所有书的平均价格
select avg(price) as 平均价格 from book
MAX最大:
列出BOOK表中最贵的书
select max(price) as 最贵书 from book
MIN最小:
select min(price) as 最便宜书 from book
交叉联接: SELECT * from table1 CROSS JOIN table2
select x.[name], y.[name] from x left join y on x.[refid] = y.id
select y.[name], x.[name] from x right join y on x.[refid] = y.id
表联接查询
SEL