Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Creation of a database table thru a stored procedure

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-12-07 : 08:08:20
nick writes "Hello there, well i need to create a simple stored procedure that it will create a new table in my database.I would like the name of the table to be passed as parameter to the procedure from my application.
What i have tried untill now is the following:

CREATE PROCEDURE SP_CREATE_TABLE @table_name varchar(100)
AS

declare @Name varchar(100)
set @Name=@table_name

GO

CREATE TABLE @Name(.....


But it seems that does not work as i get an error!
I am completely new to stored procedures so any help would be appreciated!

Thank you!"

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-12-07 : 08:23:38
Creating Table dynamically is not recommended though you can use Dynamic SQL

CREATE PROCEDURE SP_CREATE_TABLE @table_name varchar(100)
AS

declare @Name varchar(100)
set @Name=@table_name

EXEC('CREATE TABLE '+@Name+'(.....')


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -