From View to Table

  • I have some SQL background so I have used 2006 Mgmnt stuido to build a view from a vendors DB of what I want to see. Now I need help with autimatically using the query I have built to pull the data from database A and put it into database B

    Need help creatnig the table in Database B too.

  • Try this if it works for you?

    The below will copy the table structure as well as the data from

    DATABASE_A.SCHEMA_NAME.TABLE_NAME to DATABASE_B.SCHEMA_NAME.TABLE_NAME

    SELECT COLUMN_1,COLUMN_2, ETC ETC ETC

    INTO DATABASE_B.SCHEMA_NAME.TABLE_NAME

    FROM DATABASE_A.SCHEMA_NAME.TABLE_NAME

    The below will copy only the table structure from

    DATABASE_A.SCHEMA_NAME.TABLE_NAME to DATABASE_B.SCHEMA_NAME.TABLE_NAME

    SELECT COLUMN_1,COLUMN_2, ETC ETC ETC

    INTO DATABASE_B.SCHEMA_NAME.TABLE_NAME

    FROM DATABASE_A.SCHEMA_NAME.TABLE_NAME

    WHERE 1 = 0

  • Nice solution by ColdCoffee. This will work for your needs.

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • I assume what you want is what you have in your view, is that correct?

    If that's the case use COldCoffee solution but in FROM clause type in your view name instead of the underlying table name.

    _____________________________________
    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.

Viewing 4 posts - 1 through 3 (of 3 total)

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