Feeds:
Posts
Comments

Archive for June, 2009

I was looking a query that tell me a list of view using certain view from a table, and found the answer here.

See the code below. Hope this could help someone somewhere.

select view_name from INFORMATION_SCHEMA.VIEW_COLUMN_USAGE
 where column_name='ColumnNameHere'
 and table_name='TableNameHere'

Read Full Post »

I got this code snippet from my collegue , hope this can be helpful for others too

declare @dbname nvarchar(255)
set @dbname = 'databasename'
backup log @dbname with truncate_only
DBCC SHRINKDATABASE (@dbname, 0)

Read Full Post »

Simple statement to delete record a table with condition from other related table.

delete prod
from excp_amended_daily_sales_deposits prod
inner join excp_amended_daily_sales ds
on ds.id=prod.id
where  ds.status <> 'Active'
and ds.reason_code='51'

Another example

delete  hist_tbl_ASNHeaders 
from    hist_ShipmentHeader,hist_tbl_ASNHeaders
where hist_ShipmentHeader.ShipmentHeaderID=hist_tbl_ASNHeaders.fkShipmentHeaderID

Read Full Post »

%d bloggers like this: