Saturday 21 April 2012

Select Statement


How we can get the List of System Tables in DataBase?



select * from Sys.Objects where Type='s'

How we can get the list of user tables?



select * from Sys.Objects where Type='u'

How We can Get List of Store Procedures?



select * from Sys.Objects where Type='p'

How We Can Get List of Scalar Functions?



select * from Sys.Objects where Type='fn'

Query to Get List of Table Valued Functions?



select * from Sys.Objects where Type='tf'

How we can Get List of Triggers?



select * from Sys.Objects where Type='tr'

Query To Get The Column Name,DataType, And Length of columns in a Tables?



select column_name, data_type, character_maximum_length from information_schema.columns
where table_name ={Table Name}

Query to Select n Rendom Records From a Table in the Database?



SELECT TOP 3 * FROM Tbl_REGISTRATION ORDER By NEWID()

Query to Get List of Views?



select * from information_schema.views

Query to display List of All Databases in SQL Server 2005/2008?



SELECT * FROM Sys.Databases 

How to get values of identitycolumn when you are not sure about the column name which is identity column?



SELECT IDENTITYCOL  FROM TableName 

What is the name of store procedure to send Email using SQL Server 2005/2008?



sp_send_dbmail in msdb database can be used to send email using SQL Server 2005/2008


How we can add Description to the Column using Sql Command?



We can Add Description to Column using sp_addextendedproperty System Store Procedure.

Sample Command to Insert Description for Column in a Table:

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'My Description for Column Here' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'MyTableName',       @level2type=N'COLUMN',@level2name=N'ColumnName'

No comments:

Post a Comment