Click here to Skip to main content
15,889,315 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
If any sqlserver table column is not provided a value by the user ,whats the default value in it ??

if it is a space value ,then how can i set it to Null ??
can i set any default value there ?

i was firing a sql query against a table where column can accept a null value ,but as a user did not provided any value for that --- it conceded a space "" but NOT a NULL ..but i expect it to be null ,whats d problem ??
Posted
Updated 3-Mar-13 22:15pm
v2

1. If you checked Allow Nulls, It will be null when you insert without any value.
2. The value will be empty in code behind If it is Varchar data type in db
3. You can set default value (Go to design view of the table--> click on the column name --> Look into the column property and find Default value or binding--> here you can set your default value.) or
SQL
ALTER TABLE [dbo].[tbloptions] ADD  DEFAULT ('default value') FOR [Options]
 
Share this answer
 
Comments
sr_24 4-Mar-13 4:07am    
thanks
sr_24 4-Mar-13 4:14am    
i was firing a sql query against a table where column can accept a null value ,but as i user did not provided any value for that --- it was not null but space "" ..but i expect it to be null ,whats d problem ??
willington.d 4-Mar-13 4:22am    
User might given space...
If any sqlserver table column is not provided a value by the user ,whats the default value in it ??
It's not user dependent. It is totally in hands of developer/you who owns it. While creating tables in the database, you can define the default value of the fields.

Now, if nothing is send by user, you can have multiple places/ways to handle it:
1. Send desired value from frontend to DB while insertion/updation
2. Have defaults for the column in the database if nothing is passed or leave it as NULL

so, yes defaults can be there and is driven by you and not your user.
 
Share this answer
 
Comments
sr_24 4-Mar-13 4:07am    
thanks sir
sr_24 4-Mar-13 4:10am    
i mean to say if i hv not set any default value then what would it be the default value by it self
Sandeep Mewara 4-Mar-13 4:13am    
NULL only.
Not sure exactly how a user doesn't know about a TABLE, but you could start to know more about everything by querying the system:
USE [sr_database]
GO
SELECT [object_id], [name], [column_id] FROM sys.columns WHERE [object_id] > 99 ORDER BY [name]

The return is most likely to be tables that the user created. Then use the [object_id] and cross reference things that'll return other stuff that the user created, names that might still be in his memory, etc. If the "default" value comes up, he'll say to himelf ... "aha!"
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900