顯示資料庫中所有表及其資訊

2021-03-31 08:56:58 字數 1152 閱讀 3873

alter procedure dbo.storedprocedure1

asselect   (case when columnproperty( ss.id,ss.name,'isidentity')=1 then '1'else '0' end) n'標識',(case when (select count(*) from sysobjects where (name in (select name from sysindexes where (id = ss.id) and (indid in (select indid from sysindexkeys where (id = ss.id) and (colid in (select colid from syscolumns where (id = ss.id) and (name = ss.name))))))) and (xtype = 'pk'))>0 then '1' else '0' end) n'主鍵',ss.colorder n'字段序號', (case when ss.isnullable=1 then '1'else '0' end) n'允許空', s.name as n'表名',ss.name as n'欄位名' ,t.name as n'資料型別' , isnull(columnproperty(ss.id,ss.name,'scale'),0) as n'小數字數', ss.length n'占用位元組數', isnull(e.text,'') n'預設值', columnproperty(ss.id,ss.name,'precision') as n'長度',g.[value] as n'字段描述' from sysobjects s left join syscolumns ss on ss.id=s.id inner join systypes t on ( t.xtype=ss.xtype and t.name<>'sysname') inner join sysproperties g on (ss.id=g.id and ss.colid = g.**allid) inner join sysindexkeys sk on (sk.id=ss.id and sk.colid=1)  left join sys***ments e

on ss.cdefault=e.id where s.xtype='u' and s.name<>'dtproperties'

return

--by huntfox

查詢資料庫中所有的表

select from sysobjects where xtype u 查詢當前資料庫下所有使用者建立的表 xtype char 2 物件型別。可以是下列物件型別中的一種 c check 約束 d 預設值或 default 約束 f foreign key 約束 l 日誌 fn 標量函式 if 內...

清空SQL Server資料庫中所有表資料的方法

原文 清空sql server資料庫中所有表資料的方法 其實刪除資料庫中資料的方法並不複雜,為什麼我還要多此一舉呢,一是我這裡介紹的是刪除資料庫的所有資料,因為資料之間可能形成相互約束關係,刪除操作可能陷入死迴圈,二是這裡使用了微軟未正式公開的sp msforeachtable儲存過程。也許很多讀者...

Sqlserver清空資料庫中所有表資料

指令碼 1 create procedure sp deletealldata2as 3exec sp msforeachtable alter table nocheck constraint all 4 exec sp msforeachtable alter table disable tri...