Sunday, March 7, 2010

DataBase Specific Queries

Hello friends
Here are few Database Specific Queries
  • Select All Database list 
1: SELECT [name] FROM sys.databases
2: SELECT [name] FROM sys.sysdatabases
This will Result
Select All Database list


  • Select All Tables of particular Database. 
1: SELECT Name, type,type_desc FROM sys.objects 
2: where Type='u'
This will Result
Select All Tables of particular Database
  • Here Fields Type and Type_Desc are
Type Type_Desc
C CHECK_CONSTRAINT
D DEFAULT_CONSTRAINT
F FOREIGN_KEY_CONSTRAINT
FN SQL_SCALAR_FUNCTION
IF SQL_INLINE_TABLE_VALUED_FUNCTION
IT INTERNAL_TABLE
P SQL_STORED_PROCEDURE
PK PRIMARY_KEY_CONSTRAINT
S SYSTEM_TABLE
SQ SERVICE_QUEUE
TF SQL_TABLE_VALUED_FUNCTION
TR SQL_TRIGGER
U USER_TABLE
UQ UNIQUE_CONSTRAINT
V VIEW
can be more than this…
  • Select Columns from particular Table
1: SELECT column_name as [Column Name],data_type as [Data Type],Character_maximum_length as [Character Maximum Length]
2: FROM information_schema.columns
3: WHERE table_name = 'table_1'
This will Result

Select Columns from particular Table
 
All The Best

No comments: