Search This Blog

Tuesday, February 23, 2010

How to alter a column name of a table using sql query

To update the column name of an sql table find the id of table from sysobjects table and update the syscolumns table as follows.

DECLARE @id INT
SELECT @id=[id] FROM sysobjects WHERE [name] = 'ContactDetails'

UPDATE syscolumns SET [name] ='Users_ID' WHERE [id]=@id AND [name] = 'UserID'

Wednesday, February 10, 2010

How to find the object dependencies using SQL Query

Below is the sql query to find dependencies of a table(ListingHdr).

SELECT TableName, DependentObject
FROM (
              SELECT DISTINCT
                  o.Name 'TableName',
                   op.Name 'DependentObject'
              FROM SysObjects o
               INNER Join SysDepends d ON d.DepId = o.Id
               INNER Join SysObjects op on op.Id = d.Id
               WHERE o.XType = 'U' and o.name = 'ListingHdr'
               GROUP BY o.Name, o.Id, op.Name
) x