T-SQL入門攻略之11-查看数据库对象

服务器上的数据库

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值