(1)--向表中添加一个字段 use tepgo create proc addd@idd int,@name char,@cityy char,@phonee int,@faxx intasdeclare @iddd intdeclare @namee chardeclare @cityyy chardeclare @phoneee intdeclare @faxxx int set @iddd=@idd set @namee=@nameset @cityyy=@cityyset @phoneee=@phoneeset @faxxx=@faxx insert into customers values(@iddd,@namee,@cityyy,@phoneee,@faxxx)go 注释: set @iddd=@idd set @namee=@nameset @cityyy=@cityyset @phoneee=@phoneeset @faxxx=@faxx set 后不能有逗号“,” 或者这几个语句改为: select @iddd=@idd, @namee=@name, @cityyy=@cityy, @phoneee=@phonee, @faxxx=@faxx select 后有逗号 declare @iddd intdeclare @namee chardeclare @cityyy chardeclare @phoneee intdeclare @faxxx int 或者 declare @iddd int,@namee char, @cityyy char, @phoneee int, @faxxx int 注意逗号 (2) 更新表inventory create proc prUpdateStatus@inventoryid int,@statusid intasupdate inventoryset statusid=@statusidwhere inventoryid=@inventoryid (3)多表查询 create procedure prListProperties@inventoryid intas select property.property property,inventoryproperty.value value,property.unit unitfrom inventoryproperty join propertyon inventoryproperty.propertyid=property.propertyidwhere inventoryproperty.inventoryid=@inventoryidgo 语法:Select tableA.a,b,c From tableA,tableB Where tableA.a=tableB.a 当两表有相同列名时,需在元素前加表名 tableA.a 。。。 单表内的模拟多表查询: Select first.a,second.a From tableA first,tableA second Where first.b = second.f (4)带返回值 create proc prGetLeaseScheduleID@InventoryId int,@LeaseScheduleId int outputasselect @LeaseScheduleId=LeaseScheduleIdfrom inventorywhere inventoryid=inventoryid declare @result intexec prgetleasescheduleid@leasescheduleid=@result output, --不要写反,跟其他语言有所不同,赋值@inventoryid=121 select @result result

评论