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
這個儲存過程將列出資料庫的所有表的建立時間:
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: 表的建立時間
轉