On the function of system table in SQL Server database

Source: Internet
Author: User
Tags log

(a) system table: stores all system information for SQL. Storing data about metadata in database services, such as what user databases the data server has, what login accounts the database server has, what tables are in the database, what fields each table has stored procedures, views, and so on, and so on, the system table General SYS begins.

(b) Knowledge of the system tables in the database, which can be used when writing SQL statements or programming. The following scenario uses the system table

1, when the database is created to determine whether the existence of the database, the creation of objects (tables, views, stored procedures, indexes, etc.) exist, there is a return, does not exist to execute the creation statement.

2, the bulk deletion of the database objects, such as a one-time deletion of a specific database of all users created tables, views, indexes and other objects, you can query the system table objects and then use the SQL statement to control the deletion.

(iii) A few important system tables

Sysxlogins: exists in the master database (users and roles in all databases) and records all accounts that can log on to SQL Server. Because the system table is not allowed to manually delete, if you want to delete the execution sp_configure ' allow update ', 1

will not take effect immediately, restart service or reconfigure with override

sysdatabases: Records all databases of the current system. This system table is only available in master data.

Systypes (per database): Store the default user types and user-defined user types in the system.

Sysusers: Records the users and roles in each database.

Sysobjects: Each object (constraint, default, log, rule, stored procedure) created in the database occupies one row in the table.

(iv) Know the system tables in the database, you can write SQL statements or in the development process through SQL statements to complete the following tasks

1. What databases are in the query database

SELECT * FROM Dbo.sysdatabases

2, query users create a database in which users create tables

SELECT * from sysobjects where xtype= ' U '

3. Querying which user-created stored procedures in a user-created database

SELECT * from sysobjects where xtype= ' P '

4. Batch generate SQL statements that delete all user tables in the database

Select ' DROP table ' + name from sysobjects where xtype= ' U '

The above mentioned, master Database system table, for our SQL programming has a great help

Related Article

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.