Execute SQL script from command line
Take a look at the sqlcmd
utility. It allows you to execute SQL from the command line.
http://msdn.microsoft.com/en-us/library/ms162773.aspx
It's all in there in the documentation, but the syntax should look something like this:
sqlcmd -U myLogin -P myPassword -S MyServerName -d MyDatabaseName
-Q "DROP TABLE MyTable"
Run SQL script via command line to remote server
-d - Specifies the database name - learn.microsoft.com/en-us/sql/tools/sqlcmd-utility – Ctznkane525
sqlcmd -S myServer\instanceName -i C:\myScript.sql -d DatabaseName
Run sql file in database from terminal
I presume that it is MYSQL. To run it from Unix / Linux environment you must do this:
$ mysql -h "server-name" -u "your_username" -p "your_password" "database-name" < "filename.sql"
There is another way:
mysql --host=localhost --user=your_username --password=your_password -e "filename.sql"
Related Topics
Oracle SQL:Timestamps in Where Clause
Oracle Insert into Table2 Then Delete from Table1, Exception If Fail
How to Drop Multiple Columns with a Single Alter Table Statement in SQL Server
How to Release Possible Postgres Row Locks
SQL Server 2008: the Columns in Table Do Not Match an Existing Primary Key or Unique Constraint
Good Reasons Not to Use a Relational Database
Difference Between Stored Procedures and User Defined Functions
How to Store a Tree in SQL Database
Remove Duplicates from SQL Union
Just Get Column Names from Hive Table
Efficient Implementation of Faceted Search in Relational Databases
SQL Server Max Statement Returns Multiple Results
" (+) = " Operator in Oracle SQL in Where Clause
Db2 - Returning the Top 5 of Each Category
Total Children Values Based on Parent
Postgresql - Using Subqueries with Alter Sequence Expressions