Search code examples
sql-serverdatabasesql-server-2000

How do I set the default database in Sql Server from code?


I can't seem to figure out how to set the default database in Sql Server from code. This can be either .Net code or T-Sql (T-Sql would be nice since it would be easy to use in any language). I searched Google and could only find how to do it in Sql Server Management Studio.


Solution

  • from: http://doc.ddart.net/mssql/sql70/sp_da-di_6.htm

    sp_defaultdb [@loginame =] 'login' , [@defdb =] 'database'