Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2003
    Posts
    30

    Question Unanswered: How to create a table with a name choose *in the fly*

    Hi guys!

    I need to create a table always that a new register is add in TABLE_ONE

    The name of this new table must by 'TABLE_' + TABLE_ONE.Cod

    It will be:
    TABLE_1
    TABLE_2
    TABLE_3
    ...

    I know this code must be in a trigger of insert... but how? I did some tests but didnt work.

    Thanks in advance.

  2. #2
    Join Date
    Jul 2002
    Location
    Village, MD
    Posts
    621
    What about this idea?

    drop table test
    go
    create table test(id int identity, code varchar(10))
    go
    create trigger tr_test on test
    for insert
    as
    declare @sql varchar(8000)
    set @sql=''
    select @sql=@sql+'create table '+code+'(id int identity)'+char(13)+char(10) from inserted
    exec(@sql)
    go

  3. #3
    Join Date
    Jan 2003
    Posts
    30

    Smile

    It Works.

    Thank you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •