Want to create a script to export Data and tables and views to a sql script

后端 未结 7 1281
梦如初夏
梦如初夏 2021-02-05 03:26

Want to create a script to export Data and tables and views to a sql script.

I have SQL Server 2008 r2.

So far I\'ve only been able to automatically generate an

相关标签:
7条回答
  • 2021-02-05 04:01

    Like @jhewlett said that will be the best way to do it. to answer the question in the comment section. no it shouldn't be a problem. Just make sure that the SQL Server Versions are the same. Had a bit of an issue not to long ago where there were two pc's with different releases of the R2 installed and couldn't restore the backup. Other thing you can also do is to script the entire database with data, but this will not be recommended as it could take a long time to generate the script and for it to finish running on the other computer.

    Or you can simply just stop the SQL server instance and copy the database away onto an external hard drive and re-attach it to the other server. just remember to start the instances after doing this step.

    0 讨论(0)
  • 2021-02-05 04:08

    I use Navicat Premium for these kind of things in mysql. It generates sql from data, tables, views and anything else. It provides tools to copy or synchronize table from one database on different server or platforms as well. For example I use it so much to transfer my tables from MySQL to a SQLite database, So easy and fast. Otherwise I had to transfer it manually with so much trouble.

    very good tool and required for any DB admin or programmer. It support MySQL, Oracle, MS SQL Server, PostgreSQL and SQLite.

    0 讨论(0)
  • 2021-02-05 04:08

    The easiest way to do this is to create a backup, copy the .bak file to the other server, and restore the backup there.

    0 讨论(0)
  • 2021-02-05 04:10

    To Generate a schema with data follow these steps.

    • Select database to generate a schema '>' right click '>' Tasks '>' Generate schema '>' click NEXT in popup window '>'
    • select DB object to generate schema and click NEXT '>'
    • Go to advance option and scroll down '>'
    • Find Type of data to script and select one option as you need. '>' and then Next Next and finish it.
    • Enjoy it.

    As in image

    0 讨论(0)
  • 2021-02-05 04:14

    Here are some options to think over (prioritised in terms of what I would recommend):-

    • A simple backup and restore will be the easiest and quickest solution;
    • Using a data scripting tool (like Red-Gate's Data Compare) could solve your needs;
      • Use the database comparison as part of Visual Studio.
    • A SSIS package could be developed to pump data back and forth between the two instances; or
    • Write your own script using the SET IDENTITY INSERT ON / OFF command for the identity seeded tables
    0 讨论(0)
  • 2021-02-05 04:19

    If you don't want to port all tables data (for example you need to port just some base data in special tables) scripting options is not useful for you. In this case you'll have two options. First is using some third parties tools such as Red-Gate and Second way is writing the script by yourself. I prefer Second option because except the expensive price of most of them i want to run just little script for little delete, update and inserting purpose. But the important problem is here: maybe the record count is too long to write scripts record by record. I Think the linked Server is good point to solve that. It's enough for describing Just Declare Linked Server as you see in Images and get new script in your source DB and write scripts with access to both source and destination DB. Attached image must be clear.

    Create New Linked Server:
    

    enter image description here

    Write Destination SQL Server Address:
    

    enter image description here

    Fill Login Info:
    

    enter image description here

    Now you have Linked Server:
    

    enter image description here

    Write script and enjoy:
    

    enter image description here

    Hope this help.

    0 讨论(0)
提交回复
热议问题