sql - Is it possible for me to use a variable in a CREATE TABLE statement? -



sql - Is it possible for me to use a variable in a CREATE TABLE statement? -

i following...

declare @tablename varchar(100) set @tablename = 'mynewtable' create table @tablename ( column1 int identity(1,1) primary key, column2 varchar(50) not null, column3 datetime )

...to parameterize table name in create table statement; when run as-is, error incorrect syntax near '@tablename'.

how can utilize variable in create table statement?

you can without dynamic sql:

declare @tablename varchar(100) set @tablename = 'mynewtable' create table testtemp ( column1 int identity(1,1) primary key, column2 varchar(50) not null, column3 datetime ) exec sp_rename testtemp , @tablename

sql sql-server tsql sql-server-2005 create-table

Comments

Popular posts from this blog

javascript - I need to update the text of a paragraph by inline edit -

javascript - THREE.js reposition vertices for RingGeometry -

assembly - What is the addressing mode for ld, add, and rjmp instructions? -