下面这个存储过程将列出数据库的所有表的创建时间: 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
<span>as</span>
begin
 
declare @script <span>as</span> nvarchar(2000)
<span>if</span> exists(select 1 from sysobjects <span>where</span> name=<span>'tab_alltables'</span>) drop table tab_alltables
create table tab_alltables (db nvarchar(1000), tab nvarchar(1000),cdate datetime)
declare c cursor <span>for</span>
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
open c
fetch c into @script
<span>while</span> @@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 <span>for</span> a particular table name
end
这个SP将产生三列:
“方科”为仿代码站ERP系列品牌,仿代码站专注于应用型程序制作,提倡“仿客”概念,仿功能而不仅仅是改代码,所有的代码都应当自行编写,争取超过原有程序。销售分析系统为仿代码站站长根据多年店铺经营经验原创制作,能够为小型店铺的进货提供有效数据支持。根据本系统的数据,可以得出一段时间内的耗货量,有助于减少货物积压所造成的不必
0
1) db: 数据库名称
2) tab : 表名称
3) cdate: 表的创建时间
Ok, 上面的T-SQL不难懂,希望对您数据库开发有帮助。
您可能感兴趣的文章:
实用T-SQL之生成当前索引数据库中的外键上
几个有用的T-SQL(1)
作者:Petter Liu
出处:http://www.cnblogs.com/wintersun/
该文章也同时发布在我的独立博客中-Petter Liu Blog。
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号