SQL Server itself cannot directly execute SQL files, but you can use commands in cmd to execute SQL files. SQL server can use xp_cmdshell to execute commands in cmd:
Run the SQL file in cmd:
(From: http://www.cnblogs.com/longer/archive/2010/05/15/1735940.html)
After reading the information and testing, you can run the following command in the CMD window to execute the SQL file:
osql -S 127.0.0.1 -U sa -P sa -i d:\test.sql
Simple Description: osql is a SQL Server command. to execute this command in cmd, the corresponding path of this command is automatically added to the system environment variable after SQL Server is installed. -S indicates the user ID of the database server to be connected.-P indicates the login password.-I indicates the path of the script file to be executed.
Run the CMD command in SQL Server:
Xp_cmdshell 'dir'
However, execution is not allowed by default, so you need to configure it first:
exec sp_configure 'show advanced options',1reconfiguregoexec sp_configure 'xp_cmdshell',1goreconfigurego