How to obtain the names of all tables in the database

Source: Internet
Author: User

How to obtain the names of all tables in the database
Each database managed by SQL Server has a view named sysobjects, Which is system-level,

Therefore, its fully qualified name is -- sys. sysobjects. This table stores not only the tables in the database, but also

All the "objects" in a database, including the table's primary keys, stored procedures, triggers, and so on, are a total of 24 types-tables

(Table, specifically "user-defined Table") is only one of the 24 types of objects:
Run the following query statement to obtain all the data contained in the sys. sysobjects view.

SELECT * FROM sys. sysobjects

After the data is obtained, note that the column named "type" indicates the object type, that is, the 24 types mentioned above.

Type
AF = Aggregate function (CLR)
C = CHECK constraint
D = DEFAULT (constraint or stand-alone)
F = foreign key constraint
FN = SQL scalar function
FS = Assembly (CLR) scalar function
FT = Assembly (CLR) table-valued function
IF = SQL inline table-valued function
IT = Internal table
P = SQL stored procedure
PC = Assembly (CLR) stored procedure
PK = primary key constraint
R = Rule (old-style, stand-alone)
RF = Replication-filter-procedure

S = System base table
SN = Synonym
SQ = Service queue
TA = Assembly (CLR) DML trigger
TF = SQL table-valued-function
TR = SQL DML trigger
U = Table (user-defined)
UQ = UNIQUE constraint
V = View
X = Extended stored procedure

The table to be named (User-Defined table) is an object of the "U" type, and sys. objects is of the "S" type ". So,

The SQL statement should be --
SELECT name FROM sys. sysobjects WHERE type = 'U'
GO

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.