Browse by Tags

Different ways to know structure of a table
28 February 08 01:51 AM | Madhivanan | 3 Comments   
You can use one of the following to know the structure of a table 1 Generate SQL Script option from Enterprise Manager/Management Studio 2 select * from information_schema.columns where table_name='table_name' 3 EXEC sp_help 'table_name' 4 EXEC sp_columns Read More...
TSQL to check whether the table has a column with the specified name?
19 September 07 03:51 PM | SQL Master | 2 Comments   
Within SQL Server 2005: if Exists( select * from sys.columns where Name = N '<ColumnName>' and Object_ID = Object_ID ( N '<TableName>' ) ) begin --write your own code print relevant code columns for existence end else begin --write your own Read More...
Getting table name from column name
15 September 07 05:23 AM | SQL Master | 2 Comments   
If you know the name of one column you want to find from which table that is originated, to retrieve the table name you can use following TSQL: SELECT CASE (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS AS c2 WHERE c2.TABLE_NAME = c1.TABLE_NAME AND Read More...
How do I find all the statistics and statistics columns on a specified object?
09 August 07 02:59 AM | SQL Master | 1 Comments   
Run this TSQL on the database where you want to obtain the statistics information: SELECT s.name AS statistics_name ,c.name AS column_name ,sc.stats_column_id FROM sys.stats AS s INNER JOIN sys.stats_columns AS sc ON s.object_id = sc.object_id AND s.stats_id Read More...
TSQL to find computed column expression columns
27 July 07 12:34 AM | SQL Master | 1 Comments   
USE <dbname>; GO SELECT OBJECT_NAME(d.referenced_major_id) AS referenced_name ,COL_NAME(d.referenced_major_id, d.referenced_minor_id) AS referenced_columns ,OBJECT_NAME(referenced_major_id) AS dependent_object_name ,COL_NAME(d.object_id, d.column_id) Read More...