sqsh SQL Server 2005 execute *.sql file

2019-08-29 11:30发布

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

4条回答
smile是对你的礼貌
2楼-- · 2019-08-29 11:47

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.

查看更多
家丑人穷心不美
3楼-- · 2019-08-29 11:52

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楼-- · 2019-08-29 11:57
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
查看更多
戒情不戒烟
5楼-- · 2019-08-29 11:58

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"
查看更多
登录 后发表回答