3、部),##(全局)開頭,SQLServer連接關(guān)閉后,自動(dòng)刪除。④白定義存儲(chǔ)過(guò)程(1)語(yǔ)法:createprocedure存儲(chǔ)過(guò)程名參數(shù)聲明as執(zhí)行語(yǔ)句練習(xí)1:創(chuàng)建一個(gè)存儲(chǔ)過(guò)程實(shí)現(xiàn)兩個(gè)數(shù)相加。createproceduresp_add@numlint,@num2int,@sumintoutputasselect@sum=@numl+@num2;(2)查詢存儲(chǔ)過(guò)程:execsp_helptext'sp_add';cxcc:表示執(zhí)行。sp_helptext:存儲(chǔ)過(guò)程,丿屈J:系統(tǒng)存儲(chǔ)過(guò)程,以sp_開頭(3)執(zhí)行存儲(chǔ)過(guò)程:declare@nu
4、mber1int,@number2int,@resultint;select@number1=1OCX@number2=200;execsp_add@number1,@number2,@resultoutput;select@result;(4)修改存儲(chǔ)過(guò)程:alterproceduresp_add@numlint,@num2int,@sumintoutputasselect@sum=@numl+@num2+@sum;declare@number1int,@number2int,@resultint;select@number1=100
5、,@numbcr2=200,@rcsult=1;execsp_add@number1,@number2,@resultoutput;select@result;(5)刪除存儲(chǔ)過(guò)程:dropproceduresp_add;rTwrTw9^rTwrTw?Y>9T^?TwrTw?TwrTw?Ywrrw9^rTw?Tw9T%?Tw*Yw?Tw自定義函數(shù)v£xv£xv£xv£xv£xv£xvl^v£xvl^vL^
6、v£xvl^vl^rj%rf%rj^rjwr
7、%rf%rprj*rj%rjwrj%rj*rj%rf%rj^rjwrj%rf%rj^rjwr
8、%rf%rprj^rjwrj%rj*rj^rf%rprj*rj^rf%rj^rj*rj^rjwrj%rj*rj^rf%rj^rj^rf%rprj^rf%rj%rprjwrj%rj^rf%rj^rj^rf%rprj^rf%rj%rj%rprf*rj^rf*rj^rf%rj^ry*rj^rf%系統(tǒng)白帶兩數(shù):數(shù)字型、字符型、H期型。自定義函數(shù):(1)語(yǔ)法:createfunction函數(shù)名參數(shù)聲明retu
9、rns返I叫數(shù)據(jù)類型begin語(yǔ)句return返回值end練習(xí)2:實(shí)現(xiàn)兩個(gè)數(shù)相加的兩數(shù)。createfunctionfunc_add(@numlint,@num2int)returnsintbeginreturn@numl+@num2;end【口定義函數(shù)與存儲(chǔ)過(guò)程定義的區(qū)別】①參數(shù)要用()括起來(lái)②有returns語(yǔ)句,聲明返回?cái)?shù)據(jù)類型③函數(shù)實(shí)現(xiàn)代碼要用beginend④必須return返I叫函數(shù)值(2)查詢函數(shù):execsp_helptext'func.add*;(3)執(zhí)行函數(shù):select用戶賬號(hào)名.函數(shù)名(實(shí)參)selectdbo.
10、func_add(10,20);(4)修改函數(shù):alterfunctionfunc_add(@numlint,@num2int)returnsintbeginreturn(@numl+@num2)*2;endselectdbo.func_add(10,20);(5)刪除函數(shù):dropfunctionfunc_add;練習(xí)3:創(chuàng)建一個(gè)普通的用戶myusero①創(chuàng)建一個(gè)數(shù)據(jù)庫(kù)mydb:createdatabasemydbon(name=mydb_dat,filename=,G:mydb_dat.mdf,size=2MB)logon(nam
11、e=mydb_log,filename二G:mydb_log.ldf,size=2MB);②創(chuàng)建一個(gè)登錄賬號(hào),賬號(hào)名為test,密碼為123,默認(rèn)數(shù)據(jù)庫(kù)為mydb;cxccsp_addlogin,tcst