服务器上的数据库
( 1 )方法一
select name 數據庫名 ,
database_id 數據庫 ID
from sys.databases
( 2 )方法二
Exec sp_helpdb
数据库文件
( 1 )方法一 跟當前數據庫有關
select type_desc,
name ,
physical_name,
size ,
max_size,
growth
from sys.database_files
( 2 )方法二
select name ,
physical_name
from sys.master_files
where database_id= db_id ( 'mydatabase' )
数据库的數據表
use mydatabase -- 跟當前數據庫有關
go
select *
from information_schema.tables
表結構及相關信息
use mydatabase -- 跟當前數據庫有關
go
select column_name 列名 ,
data_type 數據類型 ,
isnull ( character_maximum_length, '' ) 長度 ,
isnull ( column_default, '' ) 默認值
from information_schema.columns
where table_name= 'student'
n 获取指定 數據 表的字段数
n use mydatabase -- 跟當前數據庫有關
DECLARE @FieldNum int ;
SET @FieldNum = ( SELECT COUNT (*)
FROM information_schema.columns
WHERE TABLE_NAME= 'student' );
PRINT N' 表 student 中字段的个 數 : ' + CAST ( @FieldNum AS varchar ( 10));
go
-- 查看 當前數據庫所喲 表信息
use mydatabase -- 跟當前數據庫有關
SELECT DISTINCT table_name
FROM information_schema.columns
数据库中的視圖
use mydatabase -- 跟當前數據庫有關
go
select *
from information_schema.views
数据库中的架構
use mydatabase -- 跟當前數據庫有關
go
select
schema_name 架構名 ,
schema_owner 擁有者
from information_schema.schemata