Click here to Skip to main content
16,012,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Friends,

How to set/inset default value like Email is not available for Email column (if column value is null/empty) in Student table.

Note: I don't want to use select query.


Ex:

Student

SId SName Email Address
1 Raju raju@gmail.com bangalore
2 Reddy bangalore
3 Sita bangalore
4 Ravi ravi@gmail.com bangalore
5 Ramu bangalore

Expected Output

SId SName Email Address
1 Raju raju@gmail.com bangalore
2 Reddy Email NA bangalore
3 Sita Email NA bangalore
4 Ravi ravi@gmail.com bangalore
5 Ramu Email NA bangalore

Thanks in advance.
Posted
Updated 14-Sep-14 21:30pm
v2
Comments
Magic Wonder 15-Sep-14 3:33am    
As per your note...

Where will you want to see the expected o/p?
pradiprenushe 15-Sep-14 3:35am    
Try this
ALTER COLUMN Emailcolumnname SET DEFAULT 'Email is not available'
Member 10021658 15-Sep-14 5:10am    
Thanks for your reply. Whenever try to insert a record from front end that time I have left the Email textbox. In that situation I need to insert the record at database default value. You are given that query it will work at after record is inserted only, but I need at time of insertion.

Once again thanks.

1 solution

Set default values

SQL
CREATE TABLE Persons
(
P_Id int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Address varchar(255),
City varchar(255) DEFAULT 'Sandnes'
)


Refer
http://www.w3schools.com/sql/sql_default.asp[^]
 
Share this answer
 

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