--存储过程,在表sys.objects中
IF(EXISTS (SELECT * FROM sys.objects WHERE name = 'selPro'))
DROP PROC selPro
GO
CREATE PROC selPro(
@name varchar(20)
)
AS
--declare @tablename sysname = @name
SELECT * FROM yt1 WHERE _Name = @name
GO
ALTER PROC selPro(
@name varchar(20))
AS
--exec可执行动态sql语句,如字符串,但字符串中不能包含@变量
--EXEC ('SELECT * FROM '+ @name )
DECLARE @newname varchar(50)
SET @newname = @name
DECLARE @sql nvarchar(50)
--N同nchar的n
SET @sql = N'SELECT * FROM '+@newname
--?????不理解sp_exeutesql?????
EXEC sp_executesql @sql
GO
use test
--不带exec执行的存储过程必须是第一句!否则报错
EXEC selPro yt1
--查看存储过程实现
sp_helptext sp_execute
sql存储过程
最新推荐文章于 2023-03-24 16:48:52 发布