全球旧事资料 分类
SQLServer中常用语句
有关数据库的一写操作创建表项就不说了CREATETABLEStude
t
S
oCHAR5NOTNULLUNIQUES
ameCHAR20SsexCHAR1SageINTSdeptCHAR15
插入记录:i
serti
toStude
tS
oS
ameSsexSdeptvaluesaaamaryf172
删除记录:deletefromStude
twhereS
oaaa注:只需要删除一个主键就可以了。其他的记录会相应的删除掉。
删除表中一个字段:ALTERTABLEStude
tDROPcolum
Ssex列名
修改表中的那一行数据:原来的记录:S
oS
ameSsexSdeptaaamaryf172updateStude
tsetS
amemary1SsexmwhereS
oaaa修改后:S
oS
ameSsexSdeptaaamary1m172
desc倒叙排列:建立索引:createu
iquei
dexS
oo
Stude
tS
o索引的一点好处:在查询时候比较方便,在存在的所有记录中查找一个S
o1的时候!建立索引的表中就直接查找S
o项比较它是否1找到后查相关的记录就比较快。没有建立索引的需要把所有信息都查找一遍,再在其中找S
o字段,再比较其值1的相关记录。
默认是ASC。按表中哪个字段倒叙排序:selectfromStude
torderbyS
odesc注意:要排序的字段必须是i
t型。设置成自增长的字段在插入数据的时候不需要插入该字段的值:selectfromStude
torderbyS
odesc
f原来没有设置成自增长插入数据命令:i
serti
toStude
tS
oS
ameSsexSdeptvaluesaaamaryf172
将i
t型的S
o字段设置成自增长后i
serti
toStude
tS
ameSsexSdeptvaluesmary1f172i
serti
toStude
tS
ameSsexSdeptvaluesmar1yf172i
serti
toStude
tS
ameSsexSdeptvaluesma1ryf172i
serti
toStude
tS
ameSsexSdeptvaluesm1aryf172在表中的排序如下S
oS
ameSsexSdept1mary1f1722mar1yf1723ma1ryf1724m1aryf172
2006720查询表中记录总数:无字段名字selectcou
tfromusertable或:userid为字段名字,结果是字段的总行数selectcou
tuseridfromStude
t
查询字段的平均值:selecetavgS
ofromStude
tselectavg字段名from表名
给出查询的字段的平均值取别名selectavg字段名as别名from表名
查找指定的字段的其他字段selectSdeptSsexS
amefromStude
twhereS
o3whereS
amemary1或则whereS
amelikemary1在betwee
语句查询的都是在a
d之间的所有值而IN语句则必须是i
括号里面的值selectS
oSsexS
amefromStude
twhereSdeptbetwee
180a
d190selectS
oSsexS
amefromStude
twhereSdepti
172190查询Stude
t表中的所有的名字中的S
o和Ssex值selectS
oSsexfromStude
twhereSdept170a
dS
amelike注之间是把r
好听全球资料 返回顶部