删除根据变量确定表的存储过程
我要实现的功能是删除某个用户的某个表.
用户名和表名都是变量
create procedure delete_all
@username varchar(50),
@delete_table varchar(50)
as
execute( '
delete *
from ' +@delete_table+ '
where userID=(selecte userID from blog_users where username= '+@username)
我写的这个好像是错误的?
应该怎么写呢?谢了!
------解决方案--------------------try
create procedure delete_all
@username varchar(50),
@delete_table varchar(50)
as
execute( '
delete *
from ' +@delete_table+ '
where userID=(selecte userID from blog_users where username= ' ' '+@username + ' ' ') ')
GO
------解决方案--------------------1 delete from而不是delete * from
2 单引号之中引用单引号,需要把 '变成 ' '
create procedure delete_all
@username varchar(50),
@delete_table varchar(50)
as
execute( '
delete
from '+@delete_table+ '
where userID=(selecte userID from blog_users where username= ' ' '+@username + ' ' ')
')
GO