How to create a SQL Server 2005 timestamp field using datetime field type

A column with timestamp field type is useful to record user activity. However, as timestamp values are binary numbers it is difficult to compare with other datetime values.

A datetime column can also be used like a timestamp field to record the exact date and time by enforcing the datetime column to be not null and set its default value with getdate() function.



If you’re using Linq in your program, remember to explicitly set the Auto Generated Value property of the datetime column in the Linq to Sql designer to True after dragging the table containing the datetime field onto the .dbml view.



This is because Linq to SQL by default will not select the default value in your database and try to insert the NULL value into the datetime field. Therefore, your program will raise an error like: “Cannot insert NULL value into …”

No comments:

Post a Comment

Blog Archive

About Me

My photo
I am a software developer with roughly 5 years of experience in developing end-to-end solutions in C#, Java, C/C++, PHP and HTML/CSS/Javascript. At the moment, I am joining the Professional Doctorate in Engineering degree program in Software Technology at Eindhoven University of Technology. My areas of particular interest include software design, data structures and algorithms, problem solving, software security, embedded system, machine learning, and data science.