Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

To get table details

I want to get all table names and fields in that table from a particular database. Please help me to solve this.

like image 641
Ramdas Avatar asked May 28 '12 12:05

Ramdas


People also ask

How can I see table details in SQL?

To show table properties in the Properties window. In Object Explorer, select the table for which you want to show properties. Right-click the table and choose Properties from the shortcut menu. For more information, see Table Properties - SSMS.

How do you get data from a table?

In SQL, to retrieve data stored in our tables, we use the SELECT statement. The result of this statement is always in the form of a table that we can view with our database client software or use with programming languages to build dynamic web pages or desktop applications.

What is DESC command in SQL?

The DESC command is used to sort the data returned in descending order.


2 Answers

Try looking at the sys.objects and sys.columns tables:

SELECT * FROM SYS.OBJECTS
WHERE TYPE = 'U'

Would give you all of the tables in that database (Type U)

SELECT 'Table name : ' +  so.name, ' Column Name: ' + sc.name FROM SYS.OBJECTS so
INNER JOIN sys.columns sc ON sc.OBJECT_ID = so.OBJECT_ID
WHERE TYPE = 'U'

Would give you all of the tables in that database and the column names. You could filter on these queries and do WHERE so.name = 'Your Table'

http://msdn.microsoft.com/en-us/library/ms190324.aspx

like image 139
Darren Avatar answered Oct 14 '22 05:10

Darren


use the syntax :-sp_help your table name

like this

sp_help Payroll_Shift

enter image description here

like image 2
Mohammad Atiour Islam Avatar answered Oct 14 '22 05:10

Mohammad Atiour Islam