动态SQL
CREATE
PROC
PR_CREATETABLE
@TABLENAME
VARCHAR
(
30
)
AS
DECLARE
@SQL
VARCHAR
(
1000
)
SET
@SQL
=
'
CREATE TABLE
'
+
@TABLENAME
+
'
(ID INT,NAME VARCHAR(50))
'
EXEC
(@SQL)
GO
create
proc
p_createtable @tablename sysname
as
declare
@sql
varchar
(
8000
)
set
@sql
=
''
set
@sql
=
'
create table
'
+
@tablename
+
'
(id int primary key,name varchar(10))
'
exec
(@sql)
go
exec
p_createtable
'
tab999
'
go
insert
tab999
values
(
1
,
'
001
'
)
insert
tab999
values
(
2
,
'
002
'
)
insert
tab999
values
(
3
,
'
003
'
)
select
*
from
tab999
go
drop
table
tab999
drop
proc
p_createtable
--
-------------------------------------
(所影响的行数为
1
行)
(所影响的行数为
1
行)
(所影响的行数为
1
行)
id name
--
--------- ----------
1
001
2
002
3
003
(所影响的行数为
3
行)