T-SQL entry into the strategy to view the database object

Source: Internet
Author: User
Tags name database

Databases on the server

(1) method 1

Select name database name,

Database_id Database ID

From sys. databases

(2) method 2

Exec sp_helpdb

Database Files

(1) method 1 is related to the current database

Select type_desc,

Name,

Physical_name,

Size,

Max_size,

Growth

From sys. database_files

(2) method 2

Select name,

Physical_name

From sys. master_files

Where database_id = db_id ('mydatabas ')

Database data table

Use mydatabase -- related to the current database

Go

Select *

From information_schema.tables

Table Structure and related information

Use mydatabase -- related to the current database

Go

Select column_name column name,

Data_type data type,

Isnull (character_maximum_length, '') length,

Isnull (column_default, '') Default Value

From information_schema.columns

Where table_name = 'student'

N. Obtain the number of fields in the specified data table.

N use mydatabase -- related to the current database

DECLARE @ FieldNum int;

SET @ FieldNum = (select count (*)

FROM information_schema.columns

WHERE TABLE_NAME = 'student ');

PRINT n' number of fields in the student table: '+ CAST (@ FieldNum AS varchar (10 ));

Go

-- View the table information of the current database

Use mydatabase -- related to the current database

Select distinct table_name

FROM information_schema.columns

Database View

Use mydatabase -- related to the current database

Go

Select *

From information_schema.views

Database architecture

Use mydatabase -- related to the current database

Go

Select

Schema_name architecture name,

Owner of schema_owner

From information_schema.schemata

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.