求資料庫中所有帶資料的表

2021-04-21 08:28:45 字數 1001 閱讀 9770

//列出所有使用者表

select [name]     

from [dbo].[sysobjects]

where [type]='u'

order by [name]

//列出有記錄的表

一、select   name,rowcnt  

from   sysindexes  

where  ( objectproperty(object_id(name),   n'isusertable')   =   1 )  and (rowcnt>0)

order by name

二、set nocount on

if object_id(n'tempdb.db.#temp') is not null

drop table #temp

create table #temp (name sysname,count numeric(18))

insert into #temp

select o.name,i.rows

from sysobjects o,sysindexes i

where o.id=i.id and o.xtype='u' and i.indid<2

select count(count) 總表數,sum(count) 總記錄數 from #temp

select * from #temp where count>0

order by name

set nocount off

//列用使用者表中的欄位名

select [name]

,[id]

,[xtype]

,[length]

,[colid]

from [jiadexing].[dbo].[syscolumns]

where [id] in(select [id]     

from [dbo].[sysobjects]

where [type]='u')

清空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...

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

其實刪除資料庫中資料的方法並不複雜,為什麼我還要多此一舉呢,一是我這裡介紹的是刪除資料庫的所有資料,因為資料之間可能形成相互約束關係,刪除操作可能陷入死迴圈,二是這裡使用了微軟未正式公開的sp msforeachtable儲存過程。也許很多讀者朋友都經歷過這樣的事情 要在開發資料庫基礎上清理乙個空庫...