Import view from another database

  • I'm trying to import a view from a different database in SQL 2005. The tables already exist, so all I want is to import the view without recreating the table or deleting the existing data. The wizard options are somewhat confusing.

    I come from the Access world where you simply do File>Get external data and import everything immediately from another DB.

    What's the way of doing exactly the same in SQL 2005?

    Thanks all, a.

  • a_ud (1/10/2011)


    I'm trying to import a view from a different database in SQL 2005. The tables already exist, so all I want is to import the view without recreating the table or deleting the existing data. The wizard options are somewhat confusing.

    I come from the Access world where you simply do File>Get external data and import everything immediately from another DB.

    What's the way of doing exactly the same in SQL 2005?

    Thanks all, a.

    Btw, you posted on the 2k8 boards. You'll want to make sure you're careful about what version you post for, since the interfaces and rules can change between versions enough to negate some methods.

    In general, though, you don't import a full object in SQL except at the table level. All you do is import the definition, or script. What you'll want to do is in your old database, rt-click the view, choose script-create-new window. Copy/paste that script into a new QA window for the new DB, then hit F5 to run it and create the view in the new DB.


    - Craig Farrell

    Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

    For better assistance in answering your questions[/url] | Forum Netiquette
    For index/tuning help, follow these directions.[/url] |Tally Tables[/url]

    Twitter: @AnyWayDBA

  • I'm not clear about whether you want to import the view itself or the data that is returned by the view.

    Because the Import Wizard imports views as tables, use that to import the data into a table in the destination database.

    If you want to put the view itself in the destination database, script it as a CREATE statement and run the statement in the destination database.

    Greg

  • Thanks so much. Just a couple of questions on this:

    1. If you do Right click>Script view as>Create to..>New window, as suggested, you get a window with fuzzy code that starts with: [font="Courier New"] USE <name_old_database>[/font]

    I guess that wouldn't work, so is that all you need to replace on the new database, or am I missing something?

    2. Wouldn't it be simpler copying just the SQL statement from the view (this view is done just by SQL, no further programming or anything involved), and then creating a new view in the target DB and copying the SQL command?

  • 1. Yes, that's all you'd have to replace.

    2. It's up to you. It's just two ways to achieve the same thing.

    Greg

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

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