@manhng

Welcome to my blog!

Run Big Sql Server File

December 31, 2019 09:40

Run Big Sql Server File (edit)

https://docs.microsoft.com/en-us/sql/tools/sqlcmd-utility?view=sql-server-ver15&viewFallbackFrom=sql-server-previousversions

Standardize SQL Server T-SQL Code Formatting

Online formatterhttps://sql-format.com/

ApexSQL's Refactor: SQL query formatter directly into SSMS and Visual Studio for free

Using SQLCMD

You have to install the Client SDK Tools

Folder: C:\Program Files\Microsoft SQL Server\110\Tools\Binn\

File: SQLCMD.EXE

SQLCMD.EXE -S (local) -U myusername -P mypassword -d DBNAME_HERE -i "D:\3.sql"
"C:\Program Files\Microsoft SQL Server\110\Tools\Binn\SQLCMD.EXE" -S Localhost -U SAAccount -P YourPassword -d DEV -i "D:\1.sql"
"C:\Program Files\Microsoft SQL Server\110\Tools\Binn\SQLCMD.EXE" -S Localhost -U SAAccount -P YourPassword -d DEV -i "D:\2.sql"

How to export data as CSV format from SQL Server using SQLCMD?

https://stackoverflow.com/questions/425379/how-to-export-data-as-csv-format-from-sql-server-using-sqlcmd

sqlcmd -S MyServer -d MyDB -U SAAccount -P YourPassword -E -Q "select col1, col2, col3 from ATable" 
       -o "MyData.csv" -h-1 -s"," -w 700
  • -h-1 removes column name headers from the result
  • -s"," sets the column seperator to the comma (,)
  • -w 700 sets the row width to 700 chars (this will need to be as wide as the longest row or it will wrap to the next line)

Categories

Recent posts