How to obtain the table's primary and foreign key information step by step using the INFORMATION_SCHEMA System View

Source: Internet
Author: User
Next, in the previous article, the INFORMATION_SCHEMA view is mentioned in the SQL table structure information query including the primary and Foreign keys and self-growth. In fact, in SQL2005, Microsoft has promoted the use of the INFORMATION_SCHEMA System View instead of using sys Dongdong, of course, there is still a lot of information that can only be queried through the sys view. Here we will query the table result information.

Next, in the previous article, the INFORMATION_SCHEMA view is mentioned in the SQL table structure information query including the primary and Foreign keys and self-growth. In fact, in SQL 2005, Microsoft has promoted the use of the INFORMATION_SCHEMA System View, instead of using sys Dongdong, of course, there is still a lot of information that can only be queried through the sys view. Here we will query the table result information.

Next, in the previous article, the INFORMATION_SCHEMA view is mentioned in the SQL table structure information query including the primary and Foreign keys and self-growth. In fact, in SQL 2005, Microsoft has promoted the use of the INFORMATION_SCHEMA System View, instead of using sys Dongdong, the Hong Kong server and the U.S. server, of course, still have a lot of information that can only be queried through the sys view. Here we take the query table result as an example to illustrate the use of some major INFORMATION_SCHEMA views.

First, we need to query the column information, which requires the [INFORMATION_SCHEMA]. [COLUMNS] System View to query the information of the data column. The SQL is as follows:

View Code

SELECT c. TABLE_SCHEMA, c. TABLE_NAME, c. COLUMN_NAME, c. DATA_TYPE, c. CHARACTER_MAXIMUM_LENGTH, c. COLUMN_DEFAULT, c. IS_NULLABLE, c. NUMERIC_PRECISION, c. NUMERIC_SCALE. c. Hong Kong Space

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.