declare @i intdeclare @sum intset @i=1set @sum=0while @i<=100begin set @sum=@sum+@i set @i=@i+1endprint @sumif 1=10 print '对'else if 2=2 print '对错'else print '错'declare @today intdeclare @week nvarchar(3)set @today=25set @week= case when @today=1 then '星期一' when @today=2 then '星期二' when @today=3 then '星期三' else '错误' endprint @weekcreate table t_a(id int not null,name varchar(5))insert into t_a values(1,'a1')insert into t_a values(1,'a2')insert into t_a values(2,'a3')insert into t_a values(4,'a4')insert into t_a values(5,'a5')create table t_b(id int not null,name varchar(5))insert into t_b values(1,'b1')insert into t_b values(1,'b2')insert into t_b values(2,'b3')insert into t_b values(4,'b4')insert into t_b values(5,'b5')select * from t_aunion all select * from t_bupdate t_b set name ='b3' where name='a3'select * from t_a left join t_b on (t_a.id=t_b.id)select * from t_a right join t_b on(t_a.id=t_b.id)select * from t_a inner join t_b on(t_a.id=t_b.id)select * from t_a,t_b where t_a.id=t_b.id--删除有重复的SQLdelete from t_awhere name in ( select max(name) from t_a group by id having count(name)>1)--游标declare @id int declare f_cursor cursor for select id from t_a open f_cursorwhile @@fetch_status=0begin fetch next from f_cursor into @id print @id print 'd'endclose f_cursordeallocate f_cursor