在SQL Server上获得特定数据库中所有表的名称的最佳方法是什么?
当前回答
感谢Ray Vega,他的响应给出了数据库中的所有用户表…
Exec sp_msforeachtable 'print " ?“‘
Sp_helptext显示了底层查询,它总结为…
select * from dbo.sysobjects o
join sys.all_objects syso on o.id = syso.object_id
where OBJECTPROPERTY(o.id, 'IsUserTable') = 1
and o.category & 2 = 0
其他回答
SELECT sobjects.name
FROM sysobjects sobjects
WHERE sobjects.xtype = 'U'
下面是你可以搜索的其他对象类型的列表:
AF: Aggregate function (CLR) C: CHECK constraint D: Default or DEFAULT constraint F: FOREIGN KEY constraint L: Log FN: Scalar function FS: Assembly (CLR) scalar-function FT: Assembly (CLR) table-valued function IF: In-lined table-function IT: Internal table P: Stored procedure PC: Assembly (CLR) stored-procedure PK: PRIMARY KEY constraint (type is K) RF: Replication filter stored procedure S: System table SN: Synonym SQ: Service queue TA: Assembly (CLR) DML trigger TF: Table function TR: SQL DML Trigger TT: Table type U: User table UQ: UNIQUE constraint (type is K) V: View X: Extended stored procedure
SELECT name
FROM sysobjects
WHERE xtype='U'
ORDER BY name;
(SQL Server 2000标准;SQL Server 2005仍然支持。)
SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE='BASE TABLE'
ORDER BY TABLE_NAME
你可以用sys。对象来获取所有数据库对象。
GO
select * from sys.objects where type_desc='USER_TABLE' order by name
GO
OR
-- For all tables
select * from INFORMATION_SCHEMA.TABLES
GO
--- For user defined tables
select * from INFORMATION_SCHEMA.TABLES where TABLE_TYPE='BASE TABLE'
GO
--- For Views
select * from INFORMATION_SCHEMA.TABLES where TABLE_TYPE='VIEW'
GO
--for oracle
select tablespace_name, table_name from all_tables;
这个链接可以提供更多的信息 主题
推荐文章
- 检查SQL Server登录是否已经存在
- 我如何使用ROW_NUMBER()?
- SQL或者TSQL是图灵完备的吗?
- 如何检查表上持有哪些锁
- SQL Server数据库备份恢复到低版本
- SQL Server:过滤sp_who2的输出
- 在SQL Server上使用varchar(MAX) vs TEXT
- Visual Studio: ContextSwitchDeadlock
- 模式、表和数据库之间的区别是什么?
- Sql Server字符串到日期的转换
- 如何将SQL Azure数据库复制到本地开发服务器?
- SQL Server 2008不能用新创建的用户登录
- SQL Server中User和Login的区别
- 在参数声明中,varchar(MAX)的大小是多少?
- 数据库性能调优有哪些资源?