????9.???
???????
?????????е???
???????δ????????????????????
???????????????????
???????????
????create view v_Demo
????as
????select ......
????10?????????
????---------------------------------???????--------------------------
????--????????:???declare?????????????????@?????@???????????????м???п????????????????????????????????????????????????
????declare @name nvarchar(30) ??@age int
????--?????????
????--1?????set ?????????????????????????
????set @age=18
????set @name ='Tianjia'
????select @age??@name  --??????????
????--2?????select ?????????????????
????select @age=19??@name='Laoniu'
????--3???????????????????
????declare @sum int =18 --??????????
????select @sum= SUM(english) from Score --???????и??
????select @sum --????????
????--4????????????????
????declare @sname nvarchar(10)='????'
????declare @sage int
????select @sage=sage from student where sName=@sname
????select @sage
????--5?????print?????????????????????????????????????????
????print @sage
????11????????
????--------------------------????????????????----------------------------------
????select * from student0
????select  @@error --?????T-SQL?????????
????select @@max_connections--????????????????????
????select @@identity --???????β??????
????12??????
???????????????
???????????????????????и???????????????????е??(unit)–???????sql????????????????????????
??????Щsql??????????????????????????????С??????????
?????????裺
???????????BEGIN TRANSACTION
????????????COMMIT TRANSACTION
????????????ROLLBACK TRANSACTION
?????ж?????????????????
??????????@@ERROR??
????@@ERROR????ж??????T-SQL??????????д??????ж???????????T-SQL???????д?????????????????????
????---------------------------??????----------------------------
????declare @sumError int=0 --????????
????begin tran
????update bank set balance=balance-1000 where cId='0001'
????set @sumError=@sumError+@@error
????update bank set balance=balance+1000 where cId='0002'
????set @sumError=@sumError+@@error
????if (@sumError=0)
????commit tran --?????????????
????else
????rollback tran --?????????????
????13???洢????
?????洢????—????????????з???(????)
??????C#?????????????洢??????/?洢??????????/?????з???????
??????????if else/while/????/insert/select ???????????洢?????????
???????
????????????? – ????????б????洢???????????????
??????????黯??????? – ????????????
?????????????? – ???SQL???
????????????????? – ?????? ?洢?????????
???????洢????
???????????壬?????master???????
??????????“sp_”?????”xp_”???
?????????洢?????
????????洢???????
????CREATE  PROC[EDURE]  ?洢??????
????@????1  ???????? = ???? OUTPUT??
????@????n  ???????? = ???? OUTPUT
????AS
????SQL???
?????????????
???????????
???????????????????????????
?????????????????????
????EXEC  ??????  [????]
????----------------------??--------------------------
????if exists (select * from sys.objects where name='usp_GroupMainlist1')
????drop proc usp_GroupMainlist1
????go
????create proc usp_GroupMainlist1
????@pageIndex int?? --???
????@pageSize int?? --????
????@pageCount int output--??????????
????as
????declare @count int --????????????
????select @count =count(*) from [mainlist] --?????????????
????set @pageCount=ceiling(@count*1.0/@pageSize)
????select * from
????(select *??row_number() over(order by [date of booking] desc) as 'num' from [mainlist]) as t
????where num between(@pageSize*(@pageIndex-1)+1) and @pageSize*@pageIndex
????order by [date of booking] desc
????-------------------------------------------------------------------------------------------
????--????  
????declare @page int
????exec usp_GroupMainlist1 1??100??@page output
????select @page
????14?????ú???
????1??ISNULL(expression??value)     ???expression???null????expression???????????????value???
????2????????
????avg()  -- ???? ???????null???????????????isnull(??????0)
????sum() -- ???
????count() -- ??????
????min() -- ??С?
????max() -- ????
????3???????????????
????LEN() --?????????????
????LOWER() --?Сд
????UPPER () --??д
????LTRIM() --??????????????
????RTRIM () --??????????????
????LTRIM(RTRIM('         bb        '))
????LEFT()??RIGHT() -- ?????????
????SUBSTRING(string??start_position??length)
????-- ????string??????????start_position??????????????????е????λ?????1???????length??????????????
????SELECT  SUBSTRING('abcdef111'??2??3)
????REPLACE(string??oldstr??newstr)
????Convert(decimal(18??2)??num)--??????λС??
????4????????????
????GETDATE() --????????????
????DATEADD (datepart ?? number?? date )--?????????????????????date?????????????????number???????????datepart???????λ?????????????DATEADD(DAY?? 3??date)?????????date??3???????????DATEADD(MONTH ??-8??date)?????????date??8????????????
????DATEDIFF ( datepart ?? startdate ?? enddate ) --????????????????? datepart ???????λ???????ο?DateAdd??
????-- ?????????????? ??
????DATEPART (datepart??date)--??????????????????? ????
????DATENAME(datepart??date)--????????????????? ?????
????YEAR()
????MONTH()
????DAY()
????15??sql?????????
????5>…Select 5-1>????У?5-2>distinct??5-3>top
????1>…From ??
????2>…Where ????
????3>…Group by ??
????4>…Having ??????
????6>…Order by ??