Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get .sql file from SQL Server 2012 database

I need to get .sql files from an existing database with SQL Server 2012. Is this possible because all I see in the export option is delimited files.

Ex.) I have table1 with 30 records. I need a file that would be something like what is below. (I know my syntax is incorrect, but you should get the point).

CREATE TABLE table1 (     INSERT INTO table1 values (    .......) 
like image 397
Andrew Avatar asked Mar 31 '13 23:03

Andrew


People also ask

How do I export a database in SQL Server 2012?

Right-click on the name of the database instance you want to use, and select Export Data from the Tasks menu. Click Next. Choose SQL Server Native Client as your data source. Choose the name of the server that you want to export data from in the Server Name dropdown box.


1 Answers

If you just want to generate a .sql script you can do this by right-clicking the database in Object Explorer and choosing Tasks > Generate Scripts:

enter image description here

Then you can select database and all objects, or you can select just the table you want:

enter image description here

Then select a location, and be sure to go into Advanced before continuing:

enter image description here

Under advanced, at the very least, change types of data to script to "Schema and Data" (if the reason you are doing this rather than a proper backup is because you need to import the data into a database earlier than SQL Server 2012, you should probably change the target server version option to whatever version you're targeting):

enter image description here

If you don't have that option in Management Studio, you are probably still running the RTM version of the client tools. Full functionality has finally been made free as of SP1. Download the most recent version - SP2 - here:

http://www.microsoft.com/en-us/download/details.aspx?id=43351

(You want one of the SQLManagementStudio files.)

like image 102
Aaron Bertrand Avatar answered Sep 20 '22 19:09

Aaron Bertrand