1:查询服务器中所有数据库信息
execute sp_helpdb;
2:查看指定数据库信息
execute sp_helpdb db_sqlserver1;
select * from sys.databases where name='db_sqlserver2'
3:重命名数据库
execute sp_renamedb db_sqlserver1, db_modsql //把数据库db_sqlserver1重命名为db_modsql
4:增加数据库的数据文件
alter database db_sqlserver add file ( name=db_sqlserver_new, filename='e:\db_sqlserver_new.mdf', size=3, maxsize=8, filegrowth=10% )
alter database db_sqlserver add log file ( name=db_sqlserver_new, filename='e:\db_sqlserver_new.mdf', size=3, maxsize=8, filegrowth=10% )
6:修改数据库文件
alter database db_modsql modify file ( name=db_modsql_new_log, size=3, maxsize=5 )
7:删除数据库文件
alter database db_modsql remove file db_modsql_new_log
8:删除数据库
drop database db_modesql
删除多个数据库: drop database db_modsql1, db_modsql2
9:利用IF和SQL语句动态删除数据库
if exists(select * from dbo.sysobjects where name='db_modsql') drop database db_modsql else print('要删除的数据库不存在');