SQL取数据库表名的方法

    技术2022-05-20  32

    sp_tables

    返回当前环境下可查询的对象的列表(任何可出现在 FROM 子句中的对象)。

    语法

    sp_tables

        [   [ @table_name      = ] 'name' ]        --对象名    [ , [ @table_owner     = ] 'owner']       --表拥有者    [ , [ @table_qualifier = ] 'qualifier' ]  --数据库名    [ , [ @table_type      = ] "type" ]       --对象类型   

     

    详细情况请查看SQL帮助。

    实例用法:

    exec sp_tables @table_name='TB_Stock_Main', @table_owner='DBO', @table_qualifier='DB_Store', @table_type='''TABLE'', ''SYSTEM TABLE'', ''VIEW'' '

    其中:   DB_Store为数据库名,    TB_Stock_Main为数据库DB_Store中的一个表。

     

    下面用法一样的效果:

    select * from sysobjects where xtype= 'U '   或select * from sysobjects where objectproperty(id, 'IsUserTable ')=1


    最新回复(0)