![]() |
SQL Server is a widely used Relational Database Management System (RDBMS) that allows users to create and manage databases effectively. When working with databases in SQL Server it is essential to understand the schema of the tables present in the database. Describing a table means getting information about the structure and metadata of the table. In this article, we will learn how to describe a table in SQL Server. How to Describe a Table in SQL ServerThere are 3 methods through which we can describe a table in SQL Server:
Let’s set up an environmentTo understand how we can get the describe a table SQL Server, we will consider the table Customer as shown below:
1. Usign sp_help to Describe a Table in SQL ServerThe sp_help is a system stored procedure provided by the SQL Server, which is a built-in utility that provides a detailed description of a table or a view in SQL Server. Following is the syntax to use sp_help procedure: Syntax: EXEC sp_help 'table_name';
where:
ExampleTo describe the above table Customers using sp_help we will have to run the following query EXEC sp_help 'Customers';
Output: ![]() Output Explanation: The above query uses the system procedure help to return a detailed grid view to describe the table. The output table describes every detail for the table customer including the name of the columns, data type, precision, nullability, length, and many more information about the table customers. 2. Usign sp_columns to Describe a Table in SQL ServerThe sp_columns is another system stored procedure provided by the SQL Server which can be used to describe a table. The sp_columns system procedures returns all the details about all of the columns present in a table . Following is the syntax to use sp_columns in SQL Server: Syntax: EXEC sp_columns 'table_name';
where:
ExampleTo describe the above table Customers using sp_columns we will have to run the following query EXEC sp_columns 'Customers';
Output: ![]() Output Explanation: The following query returns an output table having 7 columns. The first 3 columns describe the ownership and the name of the table. The fourth column describes the name of each column present in the table, similarly, the next column describes the data type, type name, and precision for each column of the table. 3. Using
|
Reffered: https://www.geeksforgeeks.org
Databases |
Related |
---|
![]() |
![]() |
![]() |
![]() |
![]() |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 15 |