SQL语言查阅手册.docx

上传人:cn****1 文档编号:561937206 上传时间:2023-06-25 格式:DOCX 页数:55 大小:47.10KB
返回 下载 相关 举报
SQL语言查阅手册.docx_第1页
第1页 / 共55页
SQL语言查阅手册.docx_第2页
第2页 / 共55页
SQL语言查阅手册.docx_第3页
第3页 / 共55页
SQL语言查阅手册.docx_第4页
第4页 / 共55页
SQL语言查阅手册.docx_第5页
第5页 / 共55页
点击查看更多>>
资源描述

《SQL语言查阅手册.docx》由会员分享,可在线阅读,更多相关《SQL语言查阅手册.docx(55页珍藏版)》请在金锄头文库上搜索。

1、SQL语言查阅手册(1)批办理2(2)变量3(3)逻辑控制5(4)函数7(4.1)系统函数7(4.2)自定义函数13(5)高级盘问23(6)储存过程35(7)游标36(8)触发器50/54SQLServer数据库的高级操作批办理变量逻辑控制函数高级盘问*/批办理将多条SQL语句作为一个整体去编译,生成一个执行计划,而后,执行!理解批办理的要点在于编译,对于由多条语句构成的一个批办理,假如在编译时,此中,有一条出现语法错误,将会以致编译失败!createtablet(int,int)说明-假如多行说明中包含了批办理的表记符go-在编译的过程中代码将会被go切割成多个部分来分批编译- 多行说明的标

2、志将会被分开而以致编译犯错以下几条语句是三个特别经典的批办理你猜一下会增加几条记录!/*insertintotvalues(1,1)go*/insertintotvalues(2,2)go/*insertintotvalues(3,3)*/go盘问看增加了几条记录select*fromttruncatetablet变量- 全局变量SQLServer中全局变量由系统定义、系统保护,用户一般仅可对其进行读取!-查察SQLServer版本printversion服务器名称printservername系统错误编号insertintotvalues(a,a)printerrorinsertintotv

3、alues(a,a)iferror=245printError-SQLServer版本的语言信息printLANGUAGE一周的第一天从礼拜几算起printdatefirstCPU执行命令所耗费时间的累加printcpu_busy获得近来增加的表记列的值createtablett(aintidentity(3,10),int)insertintott(b)values(1)printidentityselect*fromtt局部变量局部变量由用户定义,仅可在同一个批办理中调用和接见declareintAgetinyintsetintAge=12printintAgedeclarestrName

4、varchar(12)selectstrName=stateprintstrNameselectau_lname,strNamefromauthors逻辑控制IF条件判断declareiintseti=12if(i10)begin-printDadadada!printDadadada!end-elsebeginprintXiaoXiao!printXiaoXiao!end-While循环控制declareiint;seti=12;printireturn;while(i18)beginprinti;seti=i+1;ifi15break;end;-CASE分支判断selectau_lname

5、,state,犹他州fromauthorswherestate=UTselectau_lname,state,密西西比州fromauthorswherestate=MIselectau_lname,state,肯塔基州fromauthorswherestate=KSselectau_lname,state,casestatewhenUTthen犹他州whenMIthen密西西比州whenKSthen肯塔基州whenCAthen加利福利亚elsestateendfromauthors(4)函数(4.1)系统函数-获得指定字符串中左起第一个字符的ASC码printascii(ABCDEF)- 依据

6、给定的ASC码获得相应的字符- printchar(65)获得给定字符串的长度printlen(abcdef)大小写变换printlower(ABCDEF)printupper(abcdef)-去空格printltrim(abcddfddf)printrtrim(abcddfddf)求绝对值printabs(-12)幂3的2次方printpower(3,2)printpower(3,3)随机数0-1000之间的随机数printrand()*1000获得圆周率printpi()- 获得系统时间printgetdate()获得3天前的时间printdateadd(day,-3,getdate()获

7、得3天后的时间printdateadd(day,3,getdate()获得3年前的时间printdateadd(year,-3,getdate()获得3年后的时间printdateadd(year,3,getdate()获得3月后的时间printdateadd(month,3,getdate()获得9小时后的时间printdateadd(hour,9,getdate()获得9分钟后的时间printdateadd(minute,9,getdate()获得指准时间之间相隔多少年printdatediff(year,2005-01-01,2008-01-01)获得指准时间之间相隔多少月printda

8、tediff(month,2005-01-01,2008-01-01)获得指准时间之间相隔多少天printdatediff(day,2005-01-01,2008-01-01)字符串合并printabc+defprintabcderprintabc+456printabc+456种类变换printabc+convert(varchar(10),456)selecttitle_id,type,pricefromtitles-字符串联接一定保证种类一致(以下语句执行将会犯错)种类变换selecttitle_id+type+pricefromtitles正确selecttitle_id+type+c

9、onvert(varchar(10),price)fromtitlesprint123+convert(varchar(3),123)print123+123printconvert(varchar(12),2005-09-01,110)获得指准时间的特定部分printyear(getdate()printmonth(getdate()printday(getdate()获得指准时间的特定部分printdatepart(year,getdate()printdatepart(month,getdate()printdatepart(day,getdate()printdatepart(hh,g

10、etdate()printdatepart(mi,getdate()printdatepart(ss,getdate()printdatepart(ms,getdate()获得指准时间的间隔部分返回跨两个指定日期的日期和时间界限数printdatediff(year,2001-01-01,2008-08-08)printdatediff(month,2001-01-01,2008-08-08)printdatediff(day,2001-01-01,2008-08-08)printdatediff(hour,2001-01-01,2008-08-08)printdatediff(mi,2001

11、-01-01,2008-08-08)printdatediff(ss,2001-01-01,2008-08-08)-在向指定日期加上一段时间的基础上,返回新的datetime值printdateadd(year,5,getdate()printdateadd(month,5,getdate()printdateadd(day,5,getdate()printdateadd(hour,5,getdate()printdateadd(mi,5,getdate()printdateadd(ss,5,getdate()-其余printhost_id()printhost_name()printdb_i

12、d(pubs)printdb_name(5)利用系统函数作为默认值拘束droptabletttcreatetablettt(stu_namevarchar(12),stu_birthdaydatetimedefault(getdate()altertabletttaddconstraintdf_ttt_stu_birthdaydefault(getdate()forstu_birthdayinsertintotttvalues(ANiu,2005-04-01)insertintotttvalues(ANiu,getdate()insertintotttvalues(AZhu,default)s

13、p_helptttselect*fromttt(4.2)自定义函数selecttitle_idfromtitleswheretype=businessselectstuff(title_id,1,3,ABB),typefromtitleswheretype=businessselectcount(title_id)fromtitleswheretype=businessselecttitle_idfromtitleswheretype=businessFROMdbo.authorsINNERJOINdbo.titleauthorON=selectau_id,count(title_id)fromtitleauthorgroupbyau_idSELECTAS作品数目FROMdbo.authorsleftouterJOINdbo.titleauthorON=GROUPBYorderby作品数目自定义函数的引子(经过这个子盘问来引入函数的作用)子盘问统计每个作者的作品数将父盘问中的作者编号传入子盘问作为盘问条件利用聚合函数count统计

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 大杂烩/其它

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号