zoukankan      html  css  js  c++  java
  • Sql:查看数据库表和表结构的语句

    T-sql

    显示表结构和字段信息的sql语句:

    exec sp_help tablename; ~~使用存储过程 sp_help

    显示数据库包含哪些表的sql语句:
    use yourDBname;
    select name from sysobjects where xtype='u';  ~~使用系统表 sysobjects

    在当前数据库中查询其他数据库的表
    use shaowu2_2013;
    select * from ac where acid not in(select acid from shaowu2_2014.dbo.ac); -- in old,but new has not this id

    ~~~数据库系统中数据库对象的引用:数据库.对象所有者.对象名  (好比: 大楼.房间.谁的.什么东西)


    --------------------------------------------------
     SqlServer判断数据库、表、存储过程、函数是否存在
    --------------------------------------------------
    判断数据库是否存在 if exists (select * from sys.databases where name = '数据库名')

    ~~~sql2008有系统表:sys.databases,而sql2000则没有 提示对象名无效

    --drop database [数据库名]

    判断某个用户表是否存在 if exists (select * from sysobjects where id = object_id(N'[表名]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)


    ~~object_id(srhname) 函数,返回某个对象的id,( 等效于: select id from sysobjects where name=@srhname )

    ~~objectproperty(sysobjectID,prop) 获取字段的属性

    --drop table [表名]


    判断存储过程是否存在 if exists (select * from sysobjects where id = object_id(N'[存储过程名]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
    ~~同上 sysobjects系统表 object_id(objname)函数,objectproperty(objId, prop)函数,数据库的对象包括:表 视图 索引 约束 存储过程 函数
    -- drop procedure [存储过程名]

    判断函数是否存在 IF OBJECT_ID (N'函数名') IS NOT NULL DROP FUNCTION dnt_split

    判断数据库是否开启了全文搜索 select databaseproperty('数据库名','isfulltextenabled')

    判断全文目录是否存在 select * from sysfulltextcatalogs where name ='全文目录名称'

  • 相关阅读:
    服务管理--systemctl命令
    dd if=/dev/zero of=的含义是什么?Linux 下的dd命令使用详解
    QML与Qt C++ 交互机制探讨与总结
    sync命令
    linux 下shell中if的“-e,-d,-f”是什么意思
    POJ 1936 All in All(模拟)
    POJ 1088 滑雪(记忆化搜索)
    POJ 3280 Cheapest Palindrome(DP 回文变形)
    POJ 3181 Dollar Dayz(高精度 动态规划)
    HDU 1114 Piggy-Bank(完全背包)
  • 原文地址:https://www.cnblogs.com/stephenykk/p/3186773.html
Copyright © 2011-2022 走看看