下面這個存儲過程將列出數據庫的所有表的創建時間: Create proc usp_alldatabases as begin declare @script as nvarchar(2000) if exists(select 1 from sysobjects where name= 'tab_alltables' ) drop table tab_alltables create table tab_alltables (d
下面這個存儲過程將列出數據庫的所有表的創建時間:
Create proc usp_alldatabases
as
begin
declare @script as nvarchar(2000)
if exists(select 1 from sysobjects where name='tab_alltables') drop table tab_alltables
create table tab_alltables (db nvarchar(1000), tab nvarchar(1000),cdate datetime)
declare c cursor for
select 'insert into tab_alltables (tab,db,cdate) select name,'''+name+ ''',crdate from ' +name+'..sysobjects where xtype=''u''' from master..sysdatabases where dbid>4
open c
fetch c into @script
while @@fetch_status=0
begin
exec (@script)
print @script
fetch c into @script
end
close c deallocate c
select * from tab_alltables --You can add your criteria here to serach for a particular table name
end
這個SP將產生三列:
1) db: 數據庫名稱
2) tab : 表名稱
3) cdate: 表的創建時間
Ok, 上面的T-SQL不難懂,希望對您數據庫開發有幫助。
您可能感興趣的文章:
實用T-SQL之生成當前索引數據庫中的外鍵上
幾個有用的T-SQL(1)
作者:Petter Liu
出處:http://www.cnblogs.com/wintersun/
該文章也同時發布在我的獨立博客中-Petter Liu Blog。
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com