Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Setting default for almost all columns in a table?
Message
From
14/07/2012 13:13:58
 
 
To
14/07/2012 12:11:22
General information
Forum:
Microsoft SQL Server
Category:
Other
Environment versions
SQL Server:
SQL Server 2005
Miscellaneous
Thread ID:
01548548
Message ID:
01548591
Views:
52
>>>In my opinion it is more than OK. I prefer no NULLs (unless a compelling reason to do so) and all columns with defaults ( makes inserts a lot easier as well )
>I did that in my VFP days, but with .NET I've stopped using the defaults in the SQL table and I set the default values in the code.
>When I add a row, I call a function that loops thru all the columns in the datatable, and based on the type, sets the default values in the datatable row.
>
>
>Why?
>
>A. I had some problems a few times with the constraints created by the default values when handling the tables in SQL
>B. I kept forgetting to do it when I added columns and sometimes I put the wrong values in.
>
>The function never misses a column or sets the default incorrectly.

I find putting it in the table design works better for me . If I need to do an alter table and add columns I need default values unless I want to allow nulls. Can't do that on front end. My sps need to be able to insert into a table and get the defaults. How can I do that if my defaults are all set on the front end?

My experience has been the reverse from yours. In my VFP days I never worried about the backend beyond columns names and data types and maybe a generated PK ( though with VFP I used a lot of GUIDs) ( and I confess I was pretty loose about just allowing nulls on everything since I handled in my remote view the creation of a properly typed blank value on new rows. )

But in .NET ( and in an environment where I use a lot of SPs and so do a lot of other people that hit the data I find I need to have the backend handle a lot - especially defaults. Currently I am doing a lot of SP work driven by SSIS against tables that originally I only hit from my VFP or C# front ends. If they allowed nulls or especially if they did not have default values I would have a lot more work on my hands.


Charles Hankey

Though a good deal is too strange to be believed, nothing is too strange to have happened.
- Thomas Hardy

Half the harm that is done in this world is due to people who want to feel important. They don't mean to do harm-- but the harm does not interest them. Or they do not see it, or they justify it because they are absorbed in the endless struggle to think well of themselves.

-- T. S. Eliot
Democracy is two wolves and a sheep voting on what to have for lunch.
Liberty is a well-armed sheep contesting the vote.
- Ben Franklin

Pardon him, Theodotus. He is a barbarian, and thinks that the customs of his tribe and island are the laws of nature.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform