Transact-SQL – Auto Increment Primary Key

By , January 12, 2009 3:06 pm

If like me you learnt SQL using MySQL, and then gone into a job and found yourself using Microsoft’s SQL Server, you’ll probably be as irritated as me to find that Transact-SQL does not feature the ‘AUTO INCREMENT’ keyword that MySQL provides. Fortunately, the solution is far easier here than it is in PostgreSQL.

All you need is to add IDENTITY(1,1) in your column definition. I’m not going to pretend to understand exactly what this does, only that it will Automatically increment and ID field for you. If anyone wants to enlighten me on exactly what it does, then feel free :)

An Example is below:

   1: CREATE TABLE dbo.myTable(
   2:     ID INT NOT NULL IDENTITY(1,1) PRIMARY KEY,
   3:     ColumnA VARCHAR(200),
   4:     ColumnB BIT
   5: )
   6:  

Windows 7 – A Pleasant Surprise

By , January 11, 2009 8:23 pm

After a few delays by Microsoft, I finally got a hold of Windows 7 Beta this morning. I must say…I’m pleasantly surprised. It certainly does seem much much better than Vista was – even at the Beta stage!

Continue reading 'Windows 7 – A Pleasant Surprise'»

Panorama Theme by Themocracy