sqsh SQL Server 2005 execute *.sql file

三世轮回 提交于 2019-12-12 02:42:10

问题


I would to drop remote SQL Server db via sqsh but, I don't know how does it works. I can connect to sql server with command:

sqsh -Ulogin -Ppass -Smssql2005

回答1:


Once you're connected to the server, you can drop a database with the command

drop database [DBName]

Assuming that there's no one connected to it, it should work. And if it doesn't, it'll tell you why.




回答2:


echo 'USE table' > script.sqsh
echo 'go' >> script.sqsh
echo 'SELECT * FROM table' >> script.sqsh
echo 'go' >> script.sqsh
sqsh -Ulogin -Ppass -Smssql2005 -i script.sqsh



回答3:


Maybe you are using the wrong tool to connect to MS SQL Server. If you are looking to connect to MS SQL Server then you can use this code:

SQLCMD -S servername -U username -P password
OR
SQLCMD -S servername -E



回答4:


The -C argument lets you specify a query to send to the SQL Server instance.

So, I think this will do what you want:

sqsh -Ulogin -Ppass -Smssql2005 -C"DROP DATABASE MyDatabase"


来源:https://stackoverflow.com/questions/8229646/sqsh-sql-server-2005-execute-sql-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!