--声明局部变量,并为之赋值declare @name varchar(8)declare @no varchar(8)declare @sex char(2)declare @age intdeclare @address varchar(20)set @name='feiniao'set @no='s253002'set @sex='男'set @age=26set @address='zdfgsadgbfxbvxcb cxv'insert into stuInfo_1(stuName,stuNo,stuSex,stuAge,stuAddress)values(@name,@no,@sex,@age,@address)declare @aa varchar(8)declare @bb varchar(8)set @aa='feiniao'select @bb=stuSeat from stuInfo_1 where [email protected]print [email protected][email protected]--查询前2条记录或前2条记录的某些列select * from stuInfo_1select top 2 * from stuInfo_1select top 2 stuName,stuAddress from stuInfo_1go--全局变量print @@ERRORprint '当前错误号'+convert(varchar(5),@@ERROR)--全局变量@@ERROR返回int值需要转换select @@SERVICENAME AS '服务器吗名称'print @@VERSION --if else语句declare @avgage floatselect @avgage=avg(stuAge)from stuInfo_1print '平均年龄'+convert(varchar(4),@avgage)if(@avgage>=26)beginprint '年龄适中'print 'hh'endelsebeginprint '年龄不合适'end--while循环语句while (1=1)beginprint 'hh'breakend--case多分支语句declare @a intset @a=3select casewhen @a<0 then '非整数'when @a=0 then '零'else '非负非零数'endprint @@ERROR--给已存在的表中添加新列alter table stuInfo_1add score numeric(4,2)select * from stuInfo_1update stuInfo_1 set score=60.23 where stuSeat=7--查询declare @age1 intselect @age1=stuAge from stuInfo_1 where stuName='娟娟'select * from stuInfo_1 where stuAge>@age1goselect * from stuInfo_1 where stuAge>(select stuAge from stuInfo_1 where stuName='娟娟')select * from stuInfo_1 where score between 50.00 and 55.20--分数在60分以上的再加2分declare @avgscore numeric(4,2)select @avgscore=avg(score) from stuInfo_1 print @avgscoreif (@avgscore>60)begin update stuInfo_1 set score =score+2select * from stuInfo_1endelsebeginupdate stuInfo_1 set score=score-2endgoselect count(*) as '应到人数' from stuInfo_1
?