Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 601
TeaDrinkingGeek Avatar asked Dec 07 '12 17:12

TeaDrinkingGeek


People also ask

How do you generate create table script for all tables in SQL Server database?

Right click on the DB_NAME -> Select Task -> Select Generate Script. Follow along the presented wizard and select all tables in that database to generate the scripts.

How to export SQL Server data to SQL script?

At that time taking the help of third-party software like SQL Recovery tool is the best way to Export SQL Server Data to SQL Script . This software has the potential to recover corrupt SQL database files (.mdf / .ndf) and directly exports the recovered files into .sql scripts without any hassle.

How do I script a table with data in SQL Server?

You can script both the schema and the data by using the "Generate Scripts" method available in SQL Server Management Studio (SSMS). However, scripting tables with data is not ideal with large databases. The generated scripts can be run on another instance of the Database Engine or any other server.

How to generate scripts in SQL Server 2008?

Open SQL Server 2008 and select the database that you want to generate the script for. In my case, I have selected the "BlogDb" database. Now right-click the database then Tasks->Generate scripts. After that a window will open. Select the database and always check "script all objects in the selected database".

How do I use the SQL Server import and Export Wizard?

To start the SQL Server Import and Export Wizard using SSMS, go to Object Explorer, right click on a database for which want to export or import data; from the context menu under the Task sub-menu, choose the Import Data or Export Data option: The latest version of SSMS can be downloaded from the Download SQL Server Management Studio (SSMS) page.


2 Answers

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

enter image description here

like image 53
John Dewey Avatar answered Sep 27 '22 21:09

John Dewey


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
like image 39
Kane Avatar answered Sep 27 '22 21:09

Kane