MS SQL Server Query metadata

Source: Internet
Author: User
Tags sql server query


Use test
--Querying all tables and schema names in the database
Select Schema_name (schema_id) as Table_schema_name, NAME as table_name from sys.tables;

Select Table_schema,table_name from INFORMATION_SCHEMA. TABLES where table_type=n ' base TABLE '

--View table column information
Select Name as column_name,
Type_name (system_type_id) as Data_type,
Max_length,
Collation_name,is_nullable from sys.all_columns where object_id = object_id (N ' UserInfo ')

Select Column_name,data_type,character_maximum_length,collation_name,is_nullable from INFORMATION_SCHEMA. COLUMNS

--system stored procedures and functions

--Returns a list of objects in the current database through a stored procedure
EXEC sys.sp_tables

--Returns multiple result sets for object common information and columns, indexes, constraints, etc.
exec sys.sp_help @objname = ' UserInfo '

--Querying column information in a table
exec sys.sp_columns @table_name =n ' userInfo ', @table_owner =n ' dbo '

--return constraint information for an object
exec sys.sp_helpconstraint @objname =n ' Dbo.userinfo '

--Returns the version information for this instance
Select SERVERPROPERTY (' ProductLevel ')

--Returns the collation of the database
Select Databasepropertyex (' Test ', ' collation ')

--Returns the properties queried by the specified object for example: Querying the UserInfo table for a primary key

Select ObjectProperty (object_id (' UserInfo '), ' Tablehasprimarykey ')

--Returns the information queried by the specified column, such as whether the query username can be empty
Select ColumnProperty (object_id (' UserInfo '), ' UserName ', ' allowsnull ')

MS SQL Server Query metadata

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.