一、while 的使用
declare @i int
set @i=0while(@i<(select count(*) from test))
begin
print @i
set @i=@i+1
end
begin end用來設置執行塊,裏面的語句是一個執行單元
二、if else和類型轉換函數convert的使用
declare @a int,@b int
set @a=1 set @b=2
if(@a>@b)
print 'MAX:'+convert(varchar,@a)
else
print 'MIN:'+convert(varchar,@b)
三、臨時表的使用
1、
declare @table table
(
num int,
country varchar(200),
area varchar(200)
)
begin
insert into @table values(100,'中國','亞洲')
insert into @table values(1,'小日本','亞洲')
insert into @table values(50,'俄羅斯','歐洲')
insert into @table values(40,'美國','美洲')
end
select * from @table
2、
創建臨時表 #my_table當前用戶的連接(有效), ##my_table所有用戶的連接(有效),
create table #my_table
(
id int,
strData varchar(20)
)
給臨時表插入數據
insert into #my_table
select classid,className from class
3、
select classid,className into #my_table1 from class
##my_table同上
4、刪除臨時表
drop table #table或##table
四、waitfor的使用
waitfor delay '00:00:05'執行完五秒後再執行print ‘good!‘
waitfor delay '00:00:05'
print ‘good!’