SQL聲明變量並賦值


1 declare @studentid  int  //聲明一個int型變量
2 set @studentid=(select id from tclass where classid= 1);//設置變量值,tclass 為任意表,classid 為表中任一字段
3 if(@studentid is not null//如果值不為空,則執行插入語句,向表tstudent插入數據
4 INSERT INTO tstudent (studentid,phoneNo)VALUES (@studentid,@phoneNo);

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM