Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Sunday, August 19, 2012 5:05 PM | 1 vote
Hi,
Is it possible to set a uniqueidentifier field (non primary key) to a default value, say 00000000-0000-0000-0000-000000000000.
Reason: I have a proc that I need to pass some value to this field, even when the field is not needed. I store several Visit types in this table (Attendance) and only one of them would use this field. And I prefer not to have to write a separate proc to accommodate this situation. What is the best way to handle this for the uniqueidentifier field? Thanks for any suggestions.
Sunday, August 19, 2012 5:30 PM ✅Answered | 1 vote
Yes, a uniqueIedentifier can have a default value, although it is more typically the newId() function.
Sunday, August 19, 2012 5:37 PM ✅Answered | 1 vote
Adding to Kent's response, you might consider using NULL to indicate the value is not applicable. The application can pass DBNull.Value in that case.
Dan Guzman, SQL Server MVP, http://weblogs.sqlteam.com/dang/
Sunday, August 19, 2012 5:52 PM
Hi Dan,
Thanks for the reply. I though about using NULL also, but I thought it may cause an issue when I wanted to link the two tables together in a query, hence the default 0000 value. I figured, if I could put a 0000 default value in the Lookup table (GroupSchedule table, has a uniqueIedentifier as a PK ) and set the GroupScheduleId field in the Primary table (Attendance, uniqueIedentifier is not the PK) I could use it to get the descriptive info for the group from the GroupSchedule table when linking it in a query.
I guess this could still work cause if I run a query and say one of the rows has the GroupScheduleId set to null, the descriptive information from the GroupSchedule table will also be null. I'll give this a shot and see how it goes. Thanks
Michael