Execute SQL files in SQL Server

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.