7

I want to insert data from an .sql file to my table in SQL. And all that with CMD.

My file contains that line:

INSERT INTO MYTABLE
VALUES (1, 2, 25, 'AK00008GP005L', '2008-04-19 11:31:00', '000', 1, 239.97, NULL, 'GH783MF', NULL, NULL);

It is possible?

Thanks.

2
  • please specify the DB and the OS Commented Apr 16, 2012 at 8:59
  • I'm using SQL server 2008 R2. My DB name is TRY. My OS is Windows 7. Commented Apr 16, 2012 at 9:07

3 Answers 3

9

You can use SQLCMD (as suggested by Sibster). Assuming the file containing the query is called insert.sql, the command in its simplest form (using NT authentication) would look something like:

sqlcmd -S <servername> -E -d <dbname - TRY> -i insert.sql

To use SQL authentication:

sqlcmd -S <servername> -U <username> -P <password> -d <dbname - TRY> -i insert.sql
Sign up to request clarification or add additional context in comments.

Comments

3

Use the sqlcmd tool from microsoft.

A example here

Comments

2

Try This:

  1. Open a command prompt window.

  2. Type: sqlcmd -S myServer\instanceName -i C:\myScript.sql

  3. Press ENTER.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.