Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to I run a single sql command from the sqlcmd prompt?

In SQL Server, if I want to run a script from the command line, I can do this

/opt/mssql-tools/bin/sqlcmd -S $DB_HOST -U $DB_USER -P $DB_PASS -d $DB_NAME -i myscript.sql

Is it possible to run just a single command without a script and get the results? For instance, if I just wanted to run

SELECT 1

How would I do that from the command line?

like image 827
Dave Avatar asked Oct 26 '25 07:10

Dave


1 Answers

I think you want the -q switch:

sqlcmd -S localhost -U MyUser -P MyPass -d MyDb -q "SELECT 1"

Documentation is here

like image 145
SEarle1986 Avatar answered Oct 29 '25 09:10

SEarle1986



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!