zoukankan      html  css  js  c++  java
  • SQLServer中列出数据库的所有表的创建时间

     
      下面这个存储过程将列出数据库的所有表的创建时间:
     
    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

  • 相关阅读:
    视频分帧
    windows开启ssh服务
    使用geopy计算经纬度表示的坐标之间的距离
    哔站视频下载
    后缀树(Suffix Tree)
    [回滚莫队] AtCoder 歴史の研究
    [长链剖分优化dp] Codeforces 1499F
    [长链剖分优化dp] BZOJ 3522/4543 Hotel
    长链剖分O(nlogn)-O(1)求K级祖先
    [数论] Codeforces 1499D The Number of Pairs
  • 原文地址:https://www.cnblogs.com/wintersun/p/2581249.html
Copyright © 2011-2022 走看看