Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Insert data from .sql file to the table with CMD

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.

like image 653
HaOx Avatar asked Jan 17 '23 22:01

HaOx


1 Answers

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
like image 144
Ed Harper Avatar answered Jan 29 '23 02:01

Ed Harper