sql语句经典用法

sql语句经典用法

ID:42597157

大小:28.50 KB

页数:3页

时间:2019-09-18

sql语句经典用法_第1页
sql语句经典用法_第2页
sql语句经典用法_第3页
资源描述:

《sql语句经典用法》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、2007-11-30查sql中as的用法搜索到的一些经典的sql语句博客分类:SQLSQLCC++C#Apple总结一些工作中用到或碰到的SQL语句,希望能与大家分享,同时也希望大家能提供更多的精妙SQL语句.....1、deletetable1from(select*fromtable2)ast2wheretable1.id=t2.id2、truncatetabletable1(不在事务日志中做记录,比deletetable快,但不能激活触发器)3、updatetable1setcolumn=column+1whereid=(selectidfromtable2)4、updateta

2、ble1setcolumn=column+1fromtable1,table2wheretable1.id=table2.id5、selecttopn[Percent]*fromtable1'输出百分比记录6、selectid,column1*column2ascolumnfromtable1'可算明白as的用法了7、select*fromtable1wherecolumn1like'SQL#_G_O'escape'#''单匹配8、selecttable1.idfromtable1wherenotexists(selecttable2.idfromtable2wheretable1.i

3、d=table2.id)'这个应该比notin快一些9、selecttable1.idfromtable1,table2wheretable1.id<>table2.id'看复合查询机制10、selecttable1.idfromtable1,table2,(selectidfromtable3)ast3wheretable1.id=table2.idandtable2.id=t3.id'有些类似[1]了......11、select*fromtable1wherecolumn1like'[A]%'orlike'[^B]%'12、select@column1=column1fromta

4、ble1;select@column1ascolumn1'存储到自定义变量13、select*fromtable1wherecontains(column1,'char1orchar2*')'全文索引14、select*fromtable1wherecontains(column1,'前有near中有near后有')15、select*fromtable1wherecontains(column1,'formsof(inflectional,go)')'派生16、select*fromtable1wherecontains(description,'isabout(appleweigh

5、t(.9),boyweight(.8),chinaweight(.7))')'权重17、select*fromtable1wherefreetext(column1,'char')'仅支持文字不支持表达式搜索18、insertintotable1selectcolumn1,count(column1)fromtable2groupbycolumn1'统计-----------------------------------------------------------------------------------------1说明:复制表(只复制结构,源表名:a新表名:b)SQL:

6、select*intobfromawhere1<>12说明:拷贝表(拷贝数据,源表名:a目标表名:b)SQL:insertintob(a,b,c)selectd,e,ffromb;3说明:显示文章、提交人和最后回复时间SQL:selecta.title,a.username,b.adddatefromtablea,(selectmax(adddate)adddatefromtablewheretable.title=a.title)b4说明:外连接查询(表名1:a表名2:b)SQL:selecta.a,a.b,a.c,b.c,b.d,b.ffromaLEFTOUTJOINbONa.a=

7、b.c5说明:日程安排提前五分钟提醒SQL:select*from日程安排wheredatediff('minute',f开始时间,getdate())>56说明:两张关联表,删除主表中已经在副表中没有的信息SQL:deletefrominfowherenotexists(select*frominfobzwhereinfo.infid=infobz.infid)7说明:从数据库中去一年的各单位电话费统计(电话费定额和电话费清单两个表来源)SQ

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。