46

How can I export my 2012 database with data to a .sql file so I can import it to a 2008 server? I've never been able to export the data only the structure.

2
  • 3
    . . If the database is small, then the SSMS "create scripts" wizard has an option to export the data as well. Just look on the "advanced" tab to find the right option. Commented Aug 21, 2013 at 10:56
  • .sql files are only used with databases that don't have robust backup options, like MySql. Commented Apr 26, 2024 at 14:22

4 Answers 4

99

You can right click on the database in management studio. then go to,

Tasks --> Generate scripts --> Advanced

There you can enable "Type of data to script" as Schema and data, then generate the script. So that your script file will be populated with your data in table.

Sign up to request clarification or add additional context in comments.

7 Comments

It is not working well when there is a Text type column inside binary data. It was scripted INSERT as unicode text so at restore makes error! (Visual FoxPro uses "memo" columns for this type of data and it is translated to "text" in SQL Server)
I'm not understanding the structure of your data. Please share your table structure and a sample data.
I just made a sample: CREATE TABLE [dbo].[IKTCS]( [IKTSSZ] [float] NOT NULL, [CSMEGNEV] [char](254) NULL, [CSITTCSATT] [char](254) NULL, [CSFILE] [text] NULL, [CSUTV] [char](254) NULL, ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO INSERT [dbo].[IKTCS] ([IKTSSZ], [CSMEGNEV], [CSITTCSATT], [CSFILE], [CSUTV]) VALUES (1, N'file', NULL, N'EߣŁB†B÷BňBóB‚matroskaB‡B…S€g /Ă?ËM›tÂM»ŚS«„', NULL)
This is a working script. You should imagine in the TEXT some special binary what contains 'characters' what made the script unworkable. I didn't made investigation what code doing this situation.
Also under Advanced, make sure you set Script for Server Version to SQL Server 2008.
|
3

This is where to get that option Type of data to script = Schema and data

Step 1

enter image description here

Step 2

enter image description here

Comments

0

Don't use .sql files for this

This is a common request from those with, say, a MySQL background, but the MySQL tools around this are actually kind of awful. SQL Server has much better options:

  1. Take a real full backup (.bak file), and then restore the backup
  2. Setup a connection between the two servers and use the "Copy Database" wizard
  3. I don't really recommend this, but in a pinch if you can handle some downtime, take the database offline (detatch it) and copy the .mdf file(s). Then bring the database back online, and the copied mdf file can be attached on the new server. It's necessary to take the db offline because otherwise some recent changes to data might still be in memory or ldf files. Taking it offline ensures everything was flushed/written.

1 Comment

Does backup file contains users and user rights? I want backup of only structure and content.
0

My DB has 250 tables. I selected 10 and was able to export the data to .sql file

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.