In this blog I am demonstrating the running the .sql files form command prompt.
Step 1
Create the table using the Sql management studio.
- CREATE TABLE tbl_Student
- (
- ID INT IDENTITY(1,1) PRIMARY KEY,
- Fname VARCHAR(100),
- Lname VARCHAR(100),
- Salary INT
- )
Step 2
- INSERT INTO tbl_Student (Fname,LName,Salary) VALUES('Rakesh','Kalluri',10000)
- INSERT INTO tbl_Student (Fname,LName,Salary) VALUES('Srujan','Kumar',15000)
- INSERT INTO tbl_Student (Fname,LName,Salary) VALUES('Raju','Bhai',17000)
- 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.