Quantcast
Channel: lavykim australia
Viewing all articles
Browse latest Browse all 32

Listing all Tables within SQLServer

$
0
0

Everything about your SQL Server databases is stored in its system tables (sysobjects, sysindexes) and SQL Server maintains at least one row in sysindexes.

The sysobjects.Name column lists the names of the objects while sysobjects.type identifies the type of object, using the following codes:

  • 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

The following SQL statement will  list all tables within a database and count the number of records within the database.

SELECT
    sysobjects.Name
    , sysindexes.Rows
FROM
    sysobjects
    INNER JOIN sysindexes
    ON sysobjects.id = sysindexes.id
WHERE
    type = 'U'
    AND sysindexes.IndId < 2
ORDER BY
    sysobjects.Name

References & Sources


Viewing all articles
Browse latest Browse all 32

Trending Articles