Get list of View,Tables and Stored Procedures in Sql Server

No.of Views2253
Bookmarked0 times
Downloads 
Votes0
By  RRaveen   On  15 Feb 2010 22:02:47
Tag : Sql Servers , How to
Get list of View,Tables and Stored Procedures in Sql Server
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Introduction

The  most of the time we need play with view and stored procedures in sql server databases.Sometime we need to know few important queries or result in sql server.

1.List of Views

2.List of Procedures

3.List of Tables

4. Find a Table

5.Find column in Tables

6.Get usefull information related tables.

Implementation

I'm going to give answer to above list of questions,lets say we have created a database there  lot's of views, how  do i list all views easliy and find a view in easier way.

To this we could use the SSMS and by the  sql query  also. Here we will how  we can  get by the query.

1.List Of Views

The Query like

{codecitation class="brush: sql; gutter: true;" width="650px"}

SELECT name,crdate FROM sysobjects WHERE xtype = 'U'
Order by crdate DESC

{/codecitation}

Result

Image Loading....

See above query  read all  object  name and created date from the  sysObjects which is XTYPE equal to 'V' it's  means views.

2.List of all Stored Procedures

To this we could use the same query which written in earlier example, but we need   change the XType from V to P. P  means system type value for Stored Procedures.

{codecitation class="brush: sql; gutter: true;" width="650px"}

SELECT name,crdate FROM sysobjects WHERE xtype = 'P'
Order by crdate DESC

{/codecitation}

Result

Image Loading....

3. List of Tables.

To this  your write like this way,

{codecitation class="brush: sql; gutter: true;" width="650px"}

SELECT name as Name,crdate as CreatedDate FROM sysobjects WHERE xtype = 'U'
Order by crdate DESC

{/codecitation}

Result

Image Loading....

4.Find table using name in sql query.

To this write query like this way

{codecitation class="brush: sql; gutter: true;" width="650px"}

SELECT name as Name,crdate as CreatedDate FROM sysobjects WHERE xtype = 'U'
and [name] LIKE '%user%'
Order by crdate DESC

{/codecitation}

In above query , i just to find all table which are  contains name like user. it's return values like followings.

Result

Image Loading....

5. Find a cloumn in Tale.

Yes this we need most of the time when we are work sql server database migration or reporting times. To this we need write query  to like followings.

{codecitation class="brush: sql; gutter: true;" width="650px"}

SELECT sysTable.name AS table_name,sysColumns.name AS column_name
FROM sys.tables AS sysTable INNER JOIN sys.columns sysColumns ON sysTable.OBJECT_ID = sysColumns.OBJECT_ID
WHERE sysColumns.name LIKE '%UserCode%'
ORDER BY table_name;

{/codecitation}

In Above query select table name ,column name from the  system table and system column which object id  eqaul in both tables. then add like statement to find column name. finally display result with order cluase by Table Name;

Result

Image Loading....

6. Finally get all usefull information about  tables.

To this we write a query to get table  informations. say  parent table name, created date, user id and etc.This is help to us find relation ship tables

{codecitation class="brush: sql; gutter: true;" width="650px"}

SELECT name,crdate as CreatedDate ,xtype as [Type],
uid as [user ID],parent_obj  as ParentTable FROM sysobjects WHERE xtype = 'U'

{/codecitation}

Result

Image Loading.....

Conclusion

This article  explorer  , about get list of views , stored procedures and tables. It's has query to find a table using name and also find column using column ane in all table in database.i hope this is help to lot.

Thank you

RRaveen

 
Sign Up to vote for this article
 
About Author
 
RRaveen
Occupation-Software Engineer
Company-TGS
Member Type-Gold
Location-Singapore
Joined date-03 Jun 2009
Home Page-codegain.com
Blog Page-www.codegain.com
- B.Sc. degree in Computer Science. - 4+ years experience in Visual C#.net and VB.net - Obsessed in OOP style design and programming. - Designing and developing Network security tools. - Designing and developing a client/server application for sharing files among users in a way other than FTP protocol. - Designing and implementing GSM gateway applications and bulk messaging. - Windows Mobile and Symbian Programming - Having knowledge with ERP solutions
 
 
Other popularSectionarticles
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top