0. 建立數據庫
CREATE DATABASE DB001
1. 建立用戶
CREATE LOGIN USER1
WITH PASSWORD = 'USER_PW';
2。 修改數據的全部者
USE DB001
exec sp_changedbowner 'USER1'
GO
3. 設置READ_COMMITTED_SNAPSHOT
ALTER DATABASE [DB001] SET READ_COMMITTED_SNAPSHOT ON
GO
4.修改字符集
ALTER DATABASE DB001 COLLATE SQL_Latin1_General_CP437_CS_AS
GO
5. 獲取全部數據庫名:
Select Name FROM Master..SysDatabases
6 . 獲取全部表名:
select name from sysobjects where type='U'
XType='U':表示全部用戶表;
XType='S':表示全部系統表;
7. 獲取全部字段名:
Select Name from SysColumns Where id=Object_Id('TableName')
8. 查看與某一個表相關的視圖、存儲過程、函數
select a.* from sysobjects a, syscomments b where a.id = b.id and b.text like '%TableName%'
9. 查詢某一個表的字段和數據類型
select column_name,data_type from information_schema.columns
where table_name = N'TableName'
10. 獲取數據庫文件路徑
select ltrim(rtrim(filename)) from dbname ..sysfiles where charindex('MDF',filename)>0
or
select ltrim(rtrim(filename)) from dbname ..sysfiles where charindex('LDF',filename)>0數據庫