Sunday 15 March 2020

sqlcmd - Run Transact-SQL Script Files

Run the script file

  • Open a command prompt window.
  • In the Command Prompt window, type: sqlcmd -S myServer\instanceName -i C:\myScript.sql
  • Press ENTER.


Save the output to a text file

  • Open a command prompt window.
  • In the Command Prompt window, type: sqlcmd -S myServer\instanceName -i C:\myScript.sql -o C:\EmpAdds.txt
  • Press ENTER.
Run the script file with the Database username and password

  • Open a command prompt window.
  • In the Command Prompt window, type: SQLCMD -S <DBServerName> -U <DBUserName> -P <DBPassword> -d <DBName> -i C:\myScript.sql -o C:\EmpAdds.txt
  • Press ENTER.
sqlcmd Utility Syntax

sqlcmd   

  •    -a packet_size  
  •    -A (dedicated administrator connection)  
  •    -b (terminate batch job if there is an error)  
  •    -c batch_terminator  
  •    -C (trust the server certificate)  
  •    -d db_name  
  •    -e (echo input)  
  •    -E (use trusted connection)  
  •    -f codepage | i:codepage[,o:codepage] | o:codepage[,i:codepage] 
  •    -g (enable column encryption) 
  •    -G (use Azure Active Directory for authentication)
  •    -h rows_per_header  
  •    -H workstation_name  
  •    -i input_file  
  •    -I (enable quoted identifiers)  
  •    -j (Print raw error messages)
  •    -k[1 | 2] (remove or replace control characters)  
  •    -K application_intent  
  •    -l login_timeout  
  •    -L[c] (list servers, optional clean output)  
  •    -m error_level  
  •    -M multisubnet_failover  
  •    -N (encrypt connection)  
  •    -o output_file  
  •    -p[1] (print statistics, optional colon format)  
  •    -P password  
  •    -q "cmdline query"  
  •    -Q "cmdline query" (and exit)  
  •    -r[0 | 1] (msgs to stderr)  
  •    -R (use client regional settings)  
  •    -s col_separator  
  •    -S [protocol:]server[instance_name][,port]  
  •    -t query_timeout  
  •    -u (unicode output file)  
  •    -U login_id  
  •    -v var = "value"  
  •    -V error_severity_level  
  •    -w column_width  
  •    -W (remove trailing spaces)  
  •    -x (disable variable substitution)  
  •    -X[1] (disable commands, startup script, environment variables, optional exit)  
  •    -y variable_length_type_display_width  
  •    -Y fixed_length_type_display_width  
  •    -z new_password   
  •    -Z new_password (and exit)  
  •    -? (usage) 



No comments:

Post a Comment

Upload valid file in C#

    protected bool CheckFileExtandLength(HttpPostedFile HtmlDocFile)     {         try         {             Dictionary<string, byte[]>...