x
login about faq Site discussion (meta-askssc)

Date Time Default Value

Hi

We have a table with five columns and one of them is a DateTime column. While inserting rows through a trigger, the value for the datetime column is inserted as '1900-01-01 00:00:000' when the value is NULL.

Kindly clarify & suggest fix.

Rgds Mohan Kumar VS

more ▼

asked Jun 27 '11 at 04:19 AM in Default

Mohan Kumar gravatar image

Mohan Kumar
204 12 18 20

(comments are locked)
10|1200 characters needed characters left

2 answers: sort voted first

For a datetime to have that value, then it will have been set to 0. If the field is nullable and you have set it to null, then it will return null.

Check if the table has default constraint.

more ▼

answered Jun 27 '11 at 04:23 AM

Kev Riley gravatar image

Kev Riley ♦♦
46.1k 38 43 69

The datetime column is designed as AllowNull. There is no default constraint.

Jun 27 '11 at 04:30 AM Mohan Kumar

Maybe something in the trigger code is replacing null with 0 then? Can you post the code?

Jun 27 '11 at 04:34 AM Kev Riley ♦♦

Thanks... The problem was within the trigger as you mentioned. Thanks again.

Jun 27 '11 at 05:36 AM Mohan Kumar
(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments



Facebook logo Follow Ask SSC on Facebook
Find Ask SSC on Google+
linkedin logo Find us on LinkedIn

Topics:

x84

asked: Jun 27 '11 at 04:19 AM

Seen: 327 times

Last Updated: Jun 27 '11 at 04:19 AM

Copyright © 2002-2012 Simple Talk Publishing. All Rights Reserved. If you have any queries, please contact the site administrators.
Ask SQL Server Central is a community service provided by Red Gate.