Data Type, The most neglected feature of SQL Server

I have been developed apps for 10 years using Microsoft SQL Server.  One of the problem i often found in my journey is a not consistent data length for same meaning data expecially if you used varchar and nvarchar. For example :

  • At table customer , you set picemail as varchar(50) while at employee you set employee email as varchar(255).
  • At table order, orderno is being set as varchar(10) while at orderdetail the field orderno is being set as varchar(20). Assuming that you not set foreign key constraint this could happen.

These could lead into problems if you don’t address. For instant if employee email is longer than 50 character then when you assign to picemail at table customer, an error will be occured

Another problem is data conversion. If you join table order and table orderdetail using orderno there will be data type conversion from varchar(10) to varchar(20). This will cut performance down up to 60%. You can read it further at :

It is as simple as create type EmailType From varchar(50) to ensure both problems goes away from the beggining.

The benefit of using this feature, in my opinion are :

  • you have a standarised data type
  • you will have no implicit data conversion
  • New member of you team will learn easly

Tag: ,

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:


You are commenting using your account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s