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