Showing posts with label Sql Server 2005. Show all posts
Showing posts with label Sql Server 2005. Show all posts

Tuesday, 28 August 2012

update two tables in one statement in SQL


UPDATE Table1
SET Table1.LastName = 'XXXXXX'
FROM Table1 T1, Table2 T2
WHERE T1.id = T2.id
and T1.id = '01'

Saturday, 8 October 2011

How to find a text inside SQL Server procedures / triggers?


1) Search in All Objects
This script search stored procedures, views, functions as well other objects.
-- Search in All Objects
SELECT OBJECT_NAME(OBJECT_ID),
definition
FROM sys.sql_modules
WHERE definition LIKE '% iID %'
GO
2) Search in Stored Procedure
This script search only stored procedure for specified column.
-- Search in Stored Procedure Only
SELECT DISTINCT OBJECT_NAME(OBJECT_ID),
object_definition(OBJECT_ID)
FROM sys.Procedures
WHERE object_definition(OBJECT_ID) LIKE '% iID %'
GO

Saturday, 1 October 2011

Find a table knowing a column name

  Exactly know the column name,
  • SELECT TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME = 'YOURCOLUMN

  if you're unsure exactly what the column is named,but you suspect you know part of the
  name, then try...
  • SELECT TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME  like  '%YOURCOLUMN%'