DBAsupport.com Forums - Powered by vBulletin
Results 1 to 6 of 6

Thread: CTAS question

  1. #1
    Join Date
    Jan 2004
    Location
    Bangalore, India
    Posts
    66

    CTAS question

    All,

    I have the following requirement:

    Table A exists.
    Table B should be a replica of Table A (structurally).

    The catch is this: Table B will have a Primary Key column and this column should be the first column, followed by all columns from Table A.

    Is the above possible through SQL? If so, please provide some hints.
    If not, please let me know ASAP, so that I can start scripting.

    Thanks!
    Suhas

  2. #2
    Join Date
    Sep 2002
    Location
    England
    Posts
    7,334
    if it has an extra column then it is not a replica

    why not just do an after insert update or delete trigger?

  3. #3
    Join Date
    Jan 2004
    Location
    Bangalore, India
    Posts
    66
    I dont want to create an exact replica, per se.
    The requirement is: Table B has one column of its own plus all columns of Table A.
    Is it possible to achieve this through SQL? The one column of Table B should be placed in position #1.
    And I dont care about data, so question of triggers arise.

  4. #4
    Join Date
    Mar 2007
    Location
    Ft. Lauderdale, FL
    Posts
    3,555
    Shall we understand you want to create an empty table which has pretty much the same structure of an existing table?

    Yes. You can do that through SQL
    Pablo (Paul) Berzukov

    Author of Understanding Database Administration available at amazon and other bookstores.

    Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.

  5. #5
    Join Date
    Nov 2000
    Location
    Pittsburgh, PA
    Posts
    4,166
    I would use a merge statement. You would not have to drop table b, its constraints or indexes. You would not need to completely recreate the table either.

    http://download.oracle.com/docs/cd/B...6.htm#i2081218

  6. #6
    Join Date
    Jul 2002
    Location
    Lake Worth, FL
    Posts
    1,492

    Talking Ctas?

    Easy does it:
    Code:
    CREATE TABLE TableB
    AS
        SELECT ROWNUM TableB_pk, TableA.* FROM TableA;
    "The person who says it cannot be done should not interrupt the person doing it." --Chinese Proverb

Posting Permissions

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


Click Here to Expand Forum to Full Width