Monday, June 06, 2005

Avoiding locks in tables

Using the 'nolock' clause we are avoiding create collisions or jam
if in that moment another task is updating the same table


update tblTable
set sinStepCodeId = 2
from tblTable
where sinStatusid in(2)

go

Select count(*) from tblTable nolock

go
...

How can we obtain all the current databases?

To list the databases available in your SQL Server and show the path of
the .MDF data files:

SELECT [name] [Database], [filename] [File Path]
FROM master..sysdatabases

Obtaining all the fields in a table

Many times we need to know the name of an field from Query Analyzer and we have open
Enterprise Manager with another task with which sometimes is difficult open another MMC->Enterprise Manager.

Forget to do this:

sp_help [table]

And try this query:

Select top 0 * from [table]


So this way you obtain each of the fields, just the name.

Deleting duplicates

How can we delete duplicate rows in a table of way fast and safe?

It's easy, if our table own defined a identity field then:


Delete from table
Where identity_field not in ( SELECT MAX( identity_field) FROM table GROUP BY [field1],[field2]...)


About me

I was born in Barcelona thirty five years ago and I am currently living in Alicante with my wife and my son. Without a doubt, they are my inspiration and my happiness.

Since I began to work in IT almost sixteen years ago I have worked in lots of positions such as Help Desk second level operator, programmer or project leader. I am very keen of data, its particularities as well as your inherent properties. I love SQL, overall SQL93 although I have worked with AS-400 or Informix.

I am consider myself a home-loving person and when I am not working in my office or destroying any system I am fully focused with my little hero called Pablo and my dear wife.