Previous note:
Starting with SQL Server 2008, we can easily export data scripts without resorting to stored procedures, but there is a slight difference in the process of exporting scripts for SQL Server 2012 and SQL Server 2008, which I'll explain here in more detail.
In SQL Server 2012, we can't directly find the option to script the data in the following illustration.
For SQL Server 2008来, we can in the Object Explorer in SSMS2008, right-click the database where you want to export the data, and in the menu that pops up, select the Generate Script option under tasks.
In the choice script that the script thinks of, select "script that writes data" to be true, and this is false by default.
Here's a detailed illustration of this process in SQL Server 2012.
I created a new database called Blogdb with only one table testtable and some messy test data in the table.
Right-click the database, select Tasks, and select Generate script.
Click Next.
Then click Next.
Don't worry about this time. Next, we first click on the "Advanced (A)" button.
We don't see a script like SQL Server 2008 that writes data, true and false, but there's a similar option, as shown in the following figure.
If we want to export the table structure and table script of the data, the type of the data to be scripted, from the schema only to the schema and data, click "OK".
We can keep the script to the file, save it to the Clipboard, or save it to a new query form, which I am personally accustomed to saving to the file.
Here you can modify the file save path, you can name the file, for example, I named the file as Blogdb.sql.
Then click Next.
Click Next.
Click Finish, then we go to the specified directory to find this file.
Open this file and we can see:
The script is the result we want.