sql server query how many tables are under the database

--Query how many tables there are in the database
SELECT count(0) from sysobjects where xtype = 'u' Copy code

explanation:
sysobjects system object table. Save the object of the current database.
Such as constraints, default values, logs, rules, stored procedures, etc.
In the database of sqlserver2005 and sqlserver2008 versions, it is now used as a view object. In each database system view, there is a sys.sysobjects view object.


Explanation of important fields of sysobjects:
sysObjects (
Name sysname, --object name
id int, --object id
xtype char(2), -- object type
type char(2), -- Object type (seems exactly the same as xtype? A bit depressing... )
uid smallint, -- ID of object owner
... -- Other fields are not commonly used.
)
Note: It should be explained that xtype and type are exactly the same, and his data is:
C = CHECK constraint
D = default value or DEFAULT constraint
F = FOREIGN KEY constraint
FN = scalar function
IF = inline table function
K = PRIMARY KEY or UNIQUE constraint
L = log
P = Stored Procedure
R = Rule
RF = Replication Filter Stored Procedure
S = System Table
TF = Table Function
TR = Trigger
U = User Table
V = View
X = Extended Stored Procedure
AF = Aggregate Function (CLR)
FS = Assembly (CLR ) ) scalar function
FT = assembly (CLR) table valued function
IF = inline table function
IT = internal table
PC = assembly (CLR) stored procedure
PK = PRIMARY KEY constraint (type is K)
SN = synonym
SQ = service queue
TA = Assembly (CLR) DML trigger
TT = table type
UQ = UNIQUE constraint (type is K)
The table contains all objects in the database, such as those tables, stored procedure views and other information

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326222858&siteId=291194637