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

二次信任 提交于 2019-12-04 08:16:57

问题


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 sqlscript for all tables and views. But the data wasn't included.

OR is there any easier way to export data, tables, views, from one SQL Server to my ISP's SQL server?

Regards Tea


回答1:


If for some reason a backup/restore won't work for you, SSMS' Generate Scripts tool includes an advanced scripting option to include data:




回答2:


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



回答3:


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




回答4:


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.




回答5:


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.




回答6:


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.




回答7:


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:

Write Destination SQL Server Address:

Fill Login Info:

Now you have Linked Server:

Write script and enjoy:

Hope this help.



来源:https://stackoverflow.com/questions/13768048/want-to-create-a-script-to-export-data-and-tables-and-views-to-a-sql-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!