Running .Sql File from Command Prompt

In this blog I am demonstrating the running the .sql files form command prompt.

Step 1

Create the table using the Sql management studio.

  1. CREATE TABLE tbl_Student  
  2. (  
  4. Fname VARCHAR(100),  
  5. Lname VARCHAR(100),  
  6. Salary INT  
  7. )  
Step 2
  1. INSERT INTO tbl_Student (Fname,LName,Salary) VALUES('Rakesh','Kalluri',10000)  
  2. INSERT INTO tbl_Student (Fname,LName,Salary) VALUES('Srujan','Kumar',15000)  
  3. INSERT INTO tbl_Student (Fname,LName,Salary) VALUES('Raju','Bhai',17000)  
  4. INSERT INTO tbl_Student (Fname,LName,Salary) VALUES('Dany','Mark',18000)  
The above script file is saved in Desktop with the file name of Student.sql. The file is saved in desktop now just we need to run the file from command prompt.

Step 3

Go to run - -> Type CMD - ? Click OK


Then command prompt will be opened.

Step 4

Syntax 1

    sqlcmd -S [Servername] -d[Databasename] -i [Filepath]

Syntax 2 (For Sql Authentication)

     sqlcmd -S[Servername] -U[Username] -P[Password] -d[Databasename] -i[Filepath]


After that check the table how many row affected.

For More information about Sqlcmd.

Type sqlcmd -? in command prompt.

show result