命名习惯 数据库名.MyDB 表名.StuInfo
数据类型
int 整形
datetime 日期 getdate()
float 浮点
bit 布尔值
nvarchar(50) 变长 文本型
nvarchar(MAX) 备注
创建数据库
create database Library
创建表
create table Users
(
UID int primary key,
userName nvarchar(20) not null,
userPwd nvarchar(20) not null
)
查询语句
select * from StuInfo
select Sex,Age from StuInfo
select * from StuInfo where Sex=‘男‘ and (Age = 21 or Age=22)
select * from StuInfo where Sex=‘男‘ and Age in(21,22)
select * from StuInfo where Age>=10 and Age<=30
select * from StuInfo where Age between 20 and 25
select top 3 StuId,Sex from StuInfo where Sex=‘男‘ order by Age desc //desc倒序
select * from StuInfo where StuId like ‘%a%‘
select COUNT(*) as UserCount from StuInfo where Sex=‘男‘ //count()统计
select MIN(Age) as MinAge from StuInfo
select MAX(Age) as MaxAge from StuInfo
select Avg(Age) as AvgAge from StuInfo //avg平均值
select * from StuInfo where Age>
(
select Avg(Age) as AvgAge from StuInfo
)
select COUNT(*) as AgeCount,Age from StuInfo Group by Age //分组
having COUNT(*)=1 order by Age
添加语句
insert into StuInfo values(‘11‘,‘吧‘,‘女‘,20,‘2005-7-30‘,‘‘,‘true‘,‘eqwe‘)
insert into StuInfo(StuId,Age) values(‘qq‘,11)
删除语句
delete StuInfo where StuId=‘qq‘
更新语句
update StuInfo set Sex=‘女‘ where ParenetId=1
联合查询
Left join right join
原文:http://www.cnblogs.com/relstart/p/4893465.html