July 8, 2010 at 10:31 am
Hi,
I have a doubt. I wanna know whether is it possible to assign a value of one column as a default value to another column using "Default" clause.
ex:
table named test_data
columns
A int
B int
c varchar(2)
I want to assign same value to both A and B. is it possible to accomplish that by using default clause.
Kindest Regards,
Paarthasarathy
Microsoft Certified Technology Specialist
http://paarthasarathyk.blogspot.com
July 8, 2010 at 10:52 am
Paarth no, you can't assign a column value as a default...it has to be a constant or results of a function.
i think you want to either use a calculated column(MyCol AS A), or a trigger if you really need to copy another columns value.
here's your table, where you can paste and see the error for yourself:
CREATE TABLE test_data(
A int,
B int ,
c int default A )
Msg 128, Level 15, State 1, Line 5
The name "A" is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted.
Lowell
July 8, 2010 at 12:02 pm
I too got the same error. thats y i posted.. 🙂
I will tell me exact requirement.. I want the columns A and C contain the same value. i actually had one of my column "A" as identity. but i had to drop the identity as there are mismatch between the columns A and C.
A lot of stored procedures has already been written with these logic.. i.e insert statements contain only B and C (A will be defaulted).now i need to alter all these SP's to insert in the A column also.
i dont want to do this way.. i need to obtain the same criterion with minimal rework.. any ideas?
Kindest Regards,
Paarthasarathy
Microsoft Certified Technology Specialist
http://paarthasarathyk.blogspot.com
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply