Create Table since a store procedure

  • Can I create a table since a store procedure in Sql 2008?

    I need to send the name of the table and in the store procedure exec the command create table with that name.

    Thanks for your help-

    Viky

  • You can do something like:

    SET ANSI_NULLS ON

    GO

    SET QUOTED_IDENTIFIER ON

    GO

    drop proc [dbo].[Make_table]

    GO

    create proc [dbo].[Make_table] @tablename varchar(512)

    as

    declare @statement varchar(7500)

    declare @table_name varchar(512)

    set @table_name = @tablename

    set @statement = ' (column1 varchar(25) not null, column2 varchar(25) not null)'

    select @statement = 'create table ' + @table_name + @statement

    exec sp_sqlexec @statement

    RETURN

    GO

    exec dbo.make_table 'dog'

    GO

    What is the business need that's driving this? There may be better ways to handle the requirement.


    And then again, I might be wrong ...
    David Webb

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply