MSSQL System Tables
MSSQL System Tables
MSSQL System Tables
System Tables
Prepared by : Ramesh
System Tables
The SQL Server system tables are broken into three parts: those tables that are only in the master
database, those that are located in each database independently, and those that are only in the
other system tables, such as the msdb database. Most of these tables are unsupported by
Microsoft Product Support for direct use. It is recommended that you use these tables for
reporting purposes only and not modify them directly. Keep in mind that these tables are likely
to change between releases or even service packs of SQL Server. If you modify them, make sure
that you back up the appropriate database. Before you can modify any system table, you must
first enable updates to the system catalog by using the sp_configure stored procedure, as shown
here:
Caution Referential integrity for system tables is handled by the tools that use it (such as
Enterprise Manager). If you make a modification to system tables, make sure the value
you're changing is a valid one.
There are a number of tables that can be found in the master database only. These tables hold
instance-level information like logins and server names.
sysaltfiles
Prepared by : Ramesh
Column Data Purpose
Type
dbid smallint Database ID that the file belongs to. This can be related to the dbid
column in the sysdatabases table.
name nchar(128) The file's logical name.
filename nchar(260) Full path and filename of the file.
syscacheobjects
The syscacheobjects table shows you how SQL Server is using its cache.
Included types:
Compiled Plan
Executable Plan
Parse Tree
Cursor Parse Tree
Extended Stored Procedure
objtype nvarchar(16) More detailed type of object. For example, this would display
whether the cached object is an ad hoc query or prepared query.
Valid types include:
Stored procedure
Prepared statement
Ad hoc query
ReplProc
Trigger
View
Default
User table
System table
Check
Rule
objid int Used to find the object in cache. For a prepared query such as a
stored procedure, this would relate to the objid in the sysobjects
table. If this is an ad hoc item in cache, this would represent an
internally generated number.
dbid smallint Database ID the cached item belongs to. This can be related to the
3
Prepared by : Ramesh
Column Data Type Purpose
dbid column in the sysdatabases table.
uid smallint If this value is -2, the cached object is from a batch not
corresponding to a user. Otherwise, this represents a user ID.
refcounts int Number of other objects that reference the cached object.
usecounts int Number of times the cached object has been used since it was
created.
pagesused int Amount of memory space in 8K pages used by the cached object.
setopts int Any time a user changes options, such as ANSI_PADDING using
the SET command,
it is stored here.
langid smallint Language ID for the cached object's creator. This relates to the
langid in the syslanguages table.
sqlbytes int Length of the procedure name or batch in cache. Used to
distinguish when first 128 bytes are the same.
Sql nvarchar(256) Stored procedure name or the first 128 bytes of the ad hoc query
submitted.
syscharsets
The syscharsets table designates which character sets and sort orders are available to SQL
Server.
sysconfigures
The sysconfigures table contains an entry for each configuration option set in SQL Server. These
options are read by the sp_configure stored procedure. Once you change the configuration of the
server, this table is adjusted and not moved to the syscurconfigs table until the server is restarted
or the RECONFIGURE command run.
Prepared by : Ramesh
Column Data Type Purpose
value int The value that the server setting is configured for when the server is
restarted or when the RECONFIGURE command is issued.
config smallint Variable number for the configuration option.
comment nvarchar(255) The name of the option.
status smallint Specifies whether the setting is static or dynamic. Possible settings
are
0 = Static
1 = Dynamic
2 = Advanced
3 = Dynamic and advanced
syscurconfigs
The syscurconfigs table is identical to the sysconfigures table. The only difference
is that the syscurconfigs table shows what settings the server is running currently, while the
sysconfigures table shows what the server will be configured for once the server is restarted or
RECONFIGURE issued. Whether you must restart or issue a RECONFIGURE command is
based on the status flag.
sysdatabases
The sysdatabases table contains a list of the databases installed on your SQL Server.
Prepared by : Ramesh
syslanguages
The syslanguages table contains a list of languages installed on the SQL Server. U.S. English is
always included.
syslockinfo
The syslockinfo table gives you a glimpse at what the SQL Server lock manager is granting locks
to. It contains information about all granted, waiting, and converting locks.
1 = NULL
2 = Database
3 = File
Prepared by : Ramesh
Column Data Type Purpose
4 = Index
5 = Table
6 = Page
7 = Key
8 = Extent
9 = Row ID (RID)
10 = Application
req_mode tinyint Type of lock requested on the resource type. There are
lots of various lock methods used, but a few of those
would include:
0 = NULL
3 = Shared
4 = Update
5 = Exclusive
req_status tinyint Represents the status of the lock's request. Values could
be any of the following:
1 = Granted
2 = Converting
3 = Waiting
req_refcnt smallint Each time the lock is requested, this number is
incremented by 1. The lock cannot be released until this is
equal to 0.
req_lifetime int Lifetime of the lock represented as a bitmap.
req_spid intint Process ID that is requesting the lock.
req_ownertype smallint Object associated with the lock such as a transaction (1)
or a cursor (2).
req_transactionID bigint Requesting transaction ID.
req_transactionUOW uniqueidentifier This column is used for DTC transactions.
syslogins
The syslogins table contains a list of logins that are assigned to the server.
Prepared by : Ramesh
Column Data Type Purpose
name varchar(30) Login ID for the user.
dbname nvarchar(128) Default database for the login when the login connects to the
server.
password navarchar(128) Login's encrypted password.
language navarchar(128) Language name that the user will use by default.
denylogin int Flag (1 if active) to deny the Windows user or group access to
the SQL Server.
has access int Flag (1 if active) to grant the Windows user or group access to
the SQL Server.
isntname int Set to 1 if the login is a Windows user or group and 0 if the login
is a SQL Server login.
isntgroup int Set to 1 if the login represents a Windows group.
isntuser int Set to 1 if the login represents a Windows user.
sysadmin int Set to 1 if the user is a member of the sysadmin server role.
securityadmin int Set to 1 if the user is a member of the securityadmin server role.
serveradmin int Set to 1 if the user is a member of the serveradmin server role.
setupadmin int Set to 1 if the user is a member of the setupadmin server role.
processadmin int Set to 1 if the user is a member of the processadmin server role.
diskadmin int Set to 1 if the user is a member of the diskadmin server role.
dbcreator int Set to 1 if the user is a member of the dbcreator server role.
loginname nvarchar(128) Name of the login. Windows logins are represented as
domainname\ loginname.
sysmessages
The sysmessages table contains a list of the available error and informational messages installed
on the SQL Server. You can use sp_addmessage to add a new message to the table.
sysoledbusers
Prepared by : Ramesh
The sysoledbusers table contains a record for each user used for linked servers.
sysperfinfo
The sysperfinfo database contains a list of performance counters used when monitoring SQL
Server in System Monitor. This table can be invaluable when you're trying to perform automated
trend analysis of your system. This table only can track the first 99 databases installed on a
server.
sysprocesses
The sysprocesses table contains a list of the system and user processes currently running on the
server. You can also see in this table how much of your system resources is being taken by the
individual process.
Prepared by : Ramesh
Column Data Type Purpose
lastwaittype nchar(32) Name of the current or last wait type.
waitresource nchar(256) Description of the lock resource.
dbid smallint Database ID that is currently using the process.
uid smallint User ID for the user who executed the command. This links to the
UID in the sysusers table in each database.
cpu int Amount of CPU the process has used.
physical_io bigint Amount of disk I/O the process has caused.
memusage int Amount of procedure cache in pages that is currently allocated to the
process. If this number is negative, the process is freeing memory
allocated to another process.
login_time datetime Represents the time when the process began. For system processes,
this will represent the time that SQL Server was started.
last_batch datetime Time of the last executed stored procedure by the client process.
ecid smallint Represents any subthreads that are operating under the process.
open_tran smallint Number of transactions currently open for the given process.
status nchar(30) Current status of the process. Some of the values you may see here
are sleeping, background, and running.
sid binary(86) Login ID for the user.
hostname nchar(128) Name of the workstation that created the process. System processes
will not have values for this setting.
program_name nchar(128) Name of the program that created the process. For example, a query
run in Query Analyzer would show the value of SQL Query
Analyzer.
hostprocess nchar(8) Process ID number for the workstation.
cmd nchar(16) Command that is currently being run against the server to create the
process.
nt_domain nchar(128) Domain name if the user is connecting with Windows
Authentication.
nt_username nchar(128) Windows user name if the user is connecting with Windows
Authentication.
net_address nchar(12) Represents the MAC address for the user who is connecting to the
system.
net_library nchar(12) Represents the method of communication to the server for the user
(for example, TCP/IP).
loginame nchar(128) The login name for the connecting user.
sysremotelogins
10
Prepared by : Ramesh
The sysremotelogins table contains information about users who are allowed to execute remote
stored procedures.
sysservers
The sysservers table contains a record for the local server as well as any linked servers or servers
participating in replication. Most of the options in this table are discussed in detail in Chapter 9.
11
Prepared by : Ramesh
Column Data Type Purpose
querytimeout int The point at which a query is timed out (in seconds).
isremote bit If this option is set to 1, the entry represents a remote
server. Otherwise it is a linked server.
rpc bit If this option is set to 1, users are allowed to make RPC
calls from the remote server.
pub bit If this option is set to 1, the remote server is a publisher.
sub bit If this option is set to 1, the remote server is a subscriber.
dist bit If this option is set to 1, the remote server is a distributor.
dpub bit If this option is set to 1, the remote server is a distributor
and a publisher.
rpcout bit If this option is set to 1, the user is allowed to make RPC
calls to the remote server.
dataaccess bit If this option is set to 1, the user is able to access data on
the remote server.
collationcompatible bit If this option is set to 1, the collation compatible option is
enabled.
system bit If this option is set to 1, enables the system option.
userremotecollation bit If this option is set to 1, specifies that the user's query will
use the remote system's collation.
lazyschemavalidation bit Turns on the lazy schema validation option. This option is
used heavily in the distributed partitioned views feature.
collation sysname Name of the collation used.
The following tables are represented in every database in SQL Server. These allow databases to
be moved from server to server without trouble. Many of these tables have views that can be
used instead of the system tables. It is much less unlikely that the views will be adjusted from
version to version where the system tables are often modified or removed.
syscolumns
There is an entry in the syscolumns table for every column in the database. The entries in this
table do include columns from the system tables.
12
Prepared by : Ramesh
Column Data Purpose
Type
id int Object's unique identifier for the column.
xtype tinyint What data type the column is storing data in. Related to the systypes
table.
xusertype smallint ID for user-defined data types if used for the column.
length smallint Maximum storage capacity for the column.
colid smallint Column or parameter ID.
cdefault int ID for the column's default value, which links to the sysobjects table.
domain int ID for the rule or CHECK constraint for the column.
colorder smallint Column order for the table.
collantionid int Collation ID for the column.
language int Language ID for the column.
status tinyint Bitmap of properties for the column.
type tinyint Type of column which is linked to the systypes table.
usertype smallint Type of user-defined data type from systypes.
prec smallint Precision of the column if applicable.
scale int Scale of the column if applicable.
iscomputed int Specifies if the column is computed with a flag of 1.
isoutparam int Specifies if the procedure parameter is an output parameter.
isnullable int Specifies if the column allows nulls.
collation sysname Collation of the column.
syscomments
The syscomments table is an important table, which holds all the stored procedures, views, rules,
triggers, DEFAULT constraints, and CHECK constraints for a given database. It is important to
never edit this table directly because it is highly dependent on sequence. If you delete one entry,
all the others that are linked to the deleted stored procedure will cease to function.
13
Prepared by : Ramesh
Column Data Type Purpose
ctext varbinary(8000) Actual text of the stored procedure in binary format.
texttype smallint 0 = User-supplied comment.
1 = System-supplied comment.
4 = Encrypted comment.
language smallint Language ID the stored procedure is in. Links to the syslanguages
table in the master database.
encrypted bit Flag indicates whether the stored procedure is encrypted. A value
of 0 means the procedure is not encrypted and 1 means it is.
compressed bit Flag indicates whether the stored procedure is compressed. A value
of 0 means the procedure is not compressed and 1 means it is.
text nvarchar(4000) The actual text for the stored procedure. This column is handy
when you need to find a stored procedure that has a certain word in
it.
sysconstraints
sysfilegroups
The sysfilegroups table includes a table for each file group used by your database.
sysfiles
The sysfiles table contains a record for each data and log file used in a given database.
14
Prepared by : Ramesh
Column Data Type Purpose
fileid smallint Unique file ID for each data and log file that your database uses.
groupid smallint File group ID that the file is a member of.
size int Size of the file in 8K pages.
maxsize int Maximum size the file can grow to in 8K pages. If the value is 0, no file
growth is allowed. If the number is -1, the file will grow until it runs out
of hard drive space.
growth int Specifies how large the increments will be that the database grows in. A
setting of 0 specifies no growth. The setting is in either pages or a
percentage of growth based on the status flag.
status int Bitmap value for the database growth.
name nchar(128) Logical name for the file.
filename nchar(260) Full path and filename for the file.
sysforeignkeys
The sysforeignkeys table contains information for any foreign keys a table may use.
sysfulltextcatalogs
The sysfulltextcatalogs table lists all the full-text catalogs in a given database.
sysindexes
15
Prepared by : Ramesh
The sysindexes table contains a indexes installed in a given table.
1 = Clustered index
>1 = Nonclustered
255 = Tables that have image or text columns.
root binary(6) For clustered indexes, the root is a pointer to the root page.
Otherwise, this is a pointer to the last page.
minlen smallint Row's minimum size.
keycnt smallint The number of keys on the index.
groupid smallint File group ID where the index was created.
dpages int Number of data pages used in the index if applicable.
reserved int Number of data pages reserved for the index where applicable.
used int Number of pages used for the index where applicable.
rowcnt bigint Number of rows in the table.
rowmodctr int Total number of inserts, deletes, and updates since the last time
statistics were updated.
xmaxlen smallint Maximum width of a row.
maxirow smallint Maximum width of a row for a nonleaf index row.
origfillfactor tinyint Original fill factor used when creating the index.
keys varbinary(1088) List of keys by their column IDs.
statblob image Binary large object (BLOB) that contains the statistics.
name sysname Name of the index.
rows int Number of rows in the table.
sysindexkeys
The sysindexkeys table maps which indexes are being used by which tables.
16
Prepared by : Ramesh
Column Data Type Purpose
keyno smallint Ordinal position of the column for the index.
sysmembers
sysobjects
The sysobjects table is one of the most important tables in the catalog. It contains a record for
each database object in it.
C = CHECK constraint
D = DEFAULT constraint
F = Foreign Key
P = Stored procedure
PK = Primary Key
S = SQL Server system table
TR = Trigger
U = User-defined table
V = View
X = Extended stored procedure
uid smallint Creator of the object.
parent_obj int Object ID for the parent of the object. For example, if you were to have
a DEFAULT constraint, its parent would be the table's object ID.
crdate datetime Date on which the object was created.
ftcatid smallint Full-text catalog ID if applicable for a table.
schema_ver int Incremented version each time the schema changes for a table.
type char(2) Type of object. The values for this are the same as the xtype column
mentioned previously.
17
Prepared by : Ramesh
syspermissions
The syspermissions provides a matrix of permissions assigned to the users, groups, or roles of a
given database. More permission information is in the sysprotects table.
sysprotects
The sysprotects table expands on the syspermissions table and specifies which type of
permissions the user has.
26 = REFERENCES
178 = CREATE FUNCTION
193 = SELECT
195 = INSERT
196 = DELETE
197 = UPDATE
198 = CREATE TABLE
203 = CREATE DATABASE
207 = CREATE VIEW
222 = CREATE PROCEDURE
224 = EXECUTE
228 = BACKUP DATABASE
233 = CREATE DEFAULT
235 = BACKUP LOG
236 = CREATE RULE
protecttype tinyint Specifies whether the user has granted access (204 and 205) to the
object or revoked access (206).
columns varbinary(4000) List of columns that have permissions applied where applicable.
grantor smallint User ID of the user who granted access in each instance.
18
Prepared by : Ramesh
sysreferences
systypes
The systypes table contains a list of system and user-defined data types.
19
Prepared by : Ramesh
sysusers
The sysusers table contains a list of users and roles in a given database.
20
Prepared by : Ramesh