我正在 MS SQL Server 2008 中创建存储过程。
在我的 SP 中,在插入语句之后,插入的行的标识值将是
生成。我在另一个插入语句中使用它。
@SID int
insert into table1(SNAME) values('Sname')
set @SID=SCOPE_IDENTITY()
insert into table2(SID)values(@SID)
在这里,我的疑问是,是否需要在 C# 代码中添加 @SID 作为参数。
如何声明一个不需要任何参数的变量?因为它正在获取值(value)
来自 SP 本身..
请帮忙
最佳答案
改变sql从
@SID int
到
DECLARE @SID int
看看DECLARE @local_variable (Transact-SQL)
Variables are declared in the body of a batch or procedure with the DECLARE statement and are assigned values by using either a SET or SELECT statement. Cursor variables can be declared with this statement and used with other cursor-related statements. After declaration, all variables are initialized as NULL, unless a valu is provided as part of the declaration.
关于c# - 如何向存储过程声明变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18228488/