martes, 21 de diciembre de 2021

How to export a MS SQL Server database to a SQL script (database to sql file) with Microsoft SQL Server

Generating .sql file of your database with data

SQL Server Management Studio provides the ability to generate scripts for creating databases, tables, stored procedures, functions, views and inserting data. For smaller amounts of data, this method can be used to send table structures and/or data to Scribe Support for testing purposes.

To proceed, Open SSMS and access the database engine with the default Windows authentication (or from the connection that you want to access):

SQL Server Management Studio SSMS Login

Connect to the server and explore the databases in the object explorer. In our case, we want to export the my_database database, that, as you can see, is available in the Databases directory:

SQL Server Management Studio Database Viewer 

Do right click on the database and select Tasks and then on Generate Scripts:

Generate Scripts SQL Server

This will open the Generate and Publish Scrips dialog. As first step, define which tables of the database you want to export, optionally you can script the entire database and objects:

Export Tables MS SQL Server Management Studio

After confirm which tables do you want to export, proceed to define if you want a single file per table or everything in a single file. If you go to the advanced scripting options, you can define the types of data to script, this means if you want to include the data on the file directly or only the structure of the database:

SQL Server Export Data and Structure

Finally, the export will begin and you will see the success message at the end:

Success SQL Server Script Structure and Data Export

 

 

https://ourcodeworld.com/articles/read/846/how-to-export-a-ms-sql-server-database-to-a-sql-script-database-to-sql-file-with-microsoft-sql-server-management-studio-17

sábado, 4 de diciembre de 2021

SQL Dump File Splitter

 https://www.rusiczki.net/2007/01/24/sql-dump-file-splitter/

Scenario: You are a conscious user and you back up your site’s database every once in a while. And you sit smiling and content knowing that your precious data is safe. Just to discover after disaster strikes that you can’t restore the contents of the SQL dump file because of upload size limitations or because phpMyAdmin would run out of memory while decompressing the gzip / zip file.

In these cases there are two solutions at hand: if you have console access you can login and import the plain SQL file (which you previously uploaded via FTP) by typing a command like “mysql -uusername -ppassword < dumpfile.sql” or if you only have access to phpMyAdmin you can open up a text editor and split the SQL file into smaller parts that can be uploaded sequentially. The problem si that if you have a larger dump file this can be a reeeaaaly time consuming job.

Today I encountered a problem like this. And since I had no console access and I was in no mood to lose a few precious hours splitting up a 40 meg file by hand I googled for “sql splitter” and I found a program called SQLDumpSplitter 2. Unfortunately the author’s site was not working (and since I don’t know any German I couldn’t really figure out why) but I found an alternative download on a dutch web developer forum. And since that forum required to be a member to be able to download I thought I should offer yet another alternative download location without all those registration related mini headaches. Here on this site…

SQLDumpSplitter 2

So here it is ladies and gentlemen: download SQLDumpSplitter 2 (or zip compressed). All credits for writing this program go to Philip Lehmann-Böhm (http://www.philiplb.de).

Slip sql files

 https://mastergt68.wordpress.com/2013/03/14/muy-buena-utilidad-para-hacer-split-de-archivos-sql/


Recientemente, tuve la necesidad de cargar un poco más de 187,000 archivos hacia SQL Server 2008 R2 SP2. Pues nada, abrir el archivo con extensión SQL desde el SQL Server Management Studio y listo. No señor; error.

Error SSMS

Bueno, habrá que hacer “split” o división en varios archivos. Yo tenía presente que en SSMS el editor de queries aguanta unas 10,000 entradas, así que procedí a ubicar un programa que me ayudase con la división y me encontré con GSplit.

Este es un programa gratuito que permite, con diversas condiciones, dividir un archivo grande en varios relacionados, que es justo lo que necesito.

Al abrir el programa, luego de descargarlo e instalarlo obviamente, se encuentra uno con esta pantalla:

GSplit 1

El programa es fácil de manejar y solo hay que indicar el archivo original, la carpeta destino y la manera en la cual las “piezas” se generarán. En mi caso en particular, definí dichas piezas de esta manera:

GSplit 2

Y en tipo y tamaño, especifiqué lo siguiente:

GSplit 3

Importante, revisar en “Other Properties” para dejarla así:

GSplit 4

Luego de esto, van al link “Split File!” y presionan Split!:

GSplit 5

Asegurense de incrementar el tamaño del buffer; en mi caso, lo dejé en 256 KB.

Luego de algunos segundos, aparece esta ventana indicando que el proceso fue exitoso:

GSplit 6