Results 1 to 4 of 4

Thread: Create Table

  1. #1
    Join Date
    Nov 2003
    Posts
    5

    Unanswered: Create Table

    Can i create a table using the structure of an existing table, instead of defining the columns one by one?

    e.g.
    I already have table1(col1 int,col2 char(3))

    I want to create another table with the same structure as table 1 without doing the following:
    create table table2(col1 int,col2 char(3))

    Is there a command of doing create table2 as table1 let say?

  2. #2
    Join Date
    Feb 2002
    Posts
    2,232
    Depending on the size of the table you could do the following:

    select * into newtable from oldtable

  3. #3
    Join Date
    Nov 2003
    Posts
    48
    if you don't want to include data in newtable, you should modify the query as below:

    select * into newtable from oldtable where 0=1

  4. #4
    Join Date
    Feb 2002
    Posts
    2,232
    Just what I was going to add:

    If you want table structure and data then

    select * into newtable from oldtable

    else

    select * into newtable from oldtable where (statement is false)

Posting Permissions

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