删除整行,同时只提供一个输入变量

时间:2012-04-06 14:57:28

标签: sql-server-2005

我有一个包含实体的表格: reg_num,user_name,phone_num,names

我想通过输入reg_num值来编写存储过程来删除行的整个数据。

create proc del @reg_num nchar(10)
as
delete reg_num, user_name, phone_num, designation from nameTable 
where reg_num = @reg_num

3 个答案:

答案 0 :(得分:0)

您没有为删除语句指定列:

create proc del @reg_num nchar(10)
as
delete from nameTable 
where reg_num = @reg_num

答案 1 :(得分:0)

您只需指定表名,不需要列出的列。

create proc del @reg_num nchar(10)
as
delete from nameTable 
where reg_num = @reg_num

另见: http://www.w3schools.com/sql/sql_delete.asp

答案 2 :(得分:0)

删除时,必须遵循以下语法:

declare @regNum int
set @regnum = 1

delete from [table] where regnum = @regnum

在存储过程中,您需要这样做:

create procedure test (@regnum int) as 
begin
delete from [table] where regnum = @regnum
end