What is the best way to get the names of all of the tables in a specific database on SQL Server?
+1
A:
SELECT name FROM sysobjects WHERE xtype='U' ORDER BY name
(sql2000 standard, still supported in 2005)
devio
2008-10-06 17:55:40
A:
SELECT sobjects.name
FROM sysobjects sobjects
WHERE sobjects.xtype = 'U'
Erikk Ross
2008-10-06 17:56:33
+7
A:
SELECT * FROM INFORMATION_SCHEMA.TABLES
or Sys.Tables
...all these sysobjects queries, and I thought I was old school =)
StingyJack
2008-10-06 17:58:19
This is the most database-agnostic way to do it :)
ranomore
2008-10-06 18:01:53
Just a note that (as mentioned in other answers) sys.tables is only available in 2005 onwards
Rob
2008-10-06 18:03:00
+11
A:
SQL Server 2005 or 2008:
SELECT * FROM information_schema.tables
SQL Server 2000:
SELECT * FROM sysobjects WHERE xtype='U'
ScottStonehouse
2008-10-06 18:00:56
+5
A:
SELECT sobjects.name
FROM sysobjects sobjects
WHERE sobjects.xtype = 'U'
Here is a list of other object types you can search for as well:
- C: Check constraint
- D: Default constraint
- F: Foreign Key constraint
- L: Log
- P: Stored procedure
- PK: Primary Key constraint
- RF: Replication Filter stored procedure
- S: System table
- TR: Trigger
- U: User table
- UQ: Unique constraint
- V: View
- X: Extended stored procedure
Micah
2008-10-06 18:02:10