Home > Database > Mysql Tutorial > SQLServer中列出数据库的所有表的创建时间

SQLServer中列出数据库的所有表的创建时间

WBOY
Release: 2016-06-07 15:51:30
Original
1667 people have browsed it

下面这个存储过程将列出数据库的所有表的创建时间: 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
Copy after login
<span>as</span>
Copy after login
begin
Copy after login
Copy after login
 
Copy after login
Copy after login
declare @script <span>as</span> nvarchar(2000)
Copy after login
<span>if</span>  exists(select 1 from sysobjects <span>where</span> name=<span>'tab_alltables'</span>) drop table tab_alltables
Copy after login
create table tab_alltables (db nvarchar(1000), tab nvarchar(1000),cdate datetime)
Copy after login
declare c cursor  <span>for</span>
Copy after login
select <span>'insert into tab_alltables (tab,db,cdate) select name,'</span><span>''</span>+name+ <span>''</span><span>',crdate from '</span> +name+<span>'..sysobjects where xtype='</span><span>'u'</span><span>''</span> from master..sysdatabases  <span>where</span> dbid>4
Copy after login
open c
Copy after login
fetch c into @script
Copy after login
Copy after login
<span>while</span> @@fetch_status=0
Copy after login
begin
Copy after login
Copy after login
exec (@script)
Copy after login
 
Copy after login
Copy after login
print @script
Copy after login
fetch c into @script
Copy after login
Copy after login
end
Copy after login
Copy after login
close c deallocate c
Copy after login
select * from tab_alltables --You can add your criteria here to serach <span>for</span> a particular table name
Copy after login
end
Copy after login
Copy after login

 

这个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。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template