How To add A column in a specified Column Order location? [Resolved]

Posted by Rajeshk under Sql Server on 4/16/2013 | Points: 10 | Views : 1191 | Status : [Member] | Replies : 10
hi all,


i want to add a column as a first row in the table how can i do that plz give me the solution,thank you

Thanks&Regards
rajeshkommireddy@gmail.com



Responses

Posted by: Learningtorise on: 4/17/2013 [Member] Starter | Points: 50

Up
0
Down

Resolved
Come on man....

You are adding column through Alter Table Query....

Add Column in table through Design Mode!!!
Right-Click on Table's Name in Object Explorer...
Select 'Modify' then table's Definition will be opened in Design Mode.

Right Click on First Column Name and select Insert Column!


Thats It...


http://hashtagakash.wordpress.com/

Rajeshk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Macki on: 4/17/2013 [Member] Starter | Points: 50

Up
0
Down

Resolved
Hi rajeshk

Try below options

Step:1----- SQL>MENUS>TOOLS>OPTIONS>DESIGNERS TAB

UNCHECK the options below

warn about tables affected
prevent saving changes that require table re-creation then click ok button


then right click of your table> script table as > drop n create to window >copy your column name n paste t in first then save it 'll works 100%



Regards
Macki

Rajeshk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Learningtorise on: 4/17/2013 [Member] Starter | Points: 25

Up
0
Down
From What I Understood From Your Query is that You wand SomeThing Like This:

DECLARE @vStr AS VARCHAR(MAX)

SELECT @vStr = COALESCE(@vStr+',', '') + [A] AS [ColumnName]
FROM B

SELECT @vStr

--- A is your column name that you want as row
--- B is TableName
--- You can put WHERE CLAUSE if you want


http://hashtagakash.wordpress.com/

Rajeshk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajeshk on: 4/17/2013 [Member] Starter | Points: 25

Up
0
Down
hi,
thank you for your response but i did not mean it what you said,actually i forgot to include one column in the table but when i am adding that column to the table it is adding at the end of the table ,but i want to add it in table as first column not as last how can do that?

Thanks&Regards
rajeshkommireddy@gmail.com

Rajeshk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajeshk on: 4/17/2013 [Member] Starter | Points: 25

Up
0
Down
yeah i already tried that it is inserting but changes are not permitting the sql server,it is throwing a error message like
save changes are not permitted,the changes you made require the following table to be dropped and recreated .

Thanks&Regards
rajeshkommireddy@gmail.com

Rajeshk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Learningtorise on: 4/17/2013 [Member] Starter | Points: 25

Up
0
Down
Hey, assign some default value to that new Column


http://hashtagakash.wordpress.com/

Rajeshk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajeshk on: 4/17/2013 [Member] Starter | Points: 25

Up
0
Down


I think you are not getting me i am unable to save the table so that i cant give default values to the column,i think i have to enable the option prevent changes to sqlserver,how do i do that? or give an appropriate command to execute,.thank you

Thanks&Regards
rajeshkommireddy@gmail.com

Rajeshk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: aswinialuri-19361 on: 4/17/2013 [Member] Starter | Points: 25

Up
0
Down
hi
better to try this
you have a Emp table like this
Id Slary Designation Name
then you need a name as second column then
then you have to write a query like this
select Id,Name,Designation,Salary instead of select * from Emp
THANKS



















Mark as Answer if it helps you
Thanks&Regards
Aswini Aluri

Rajeshk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Learningtorise on: 4/17/2013 [Member] Starter | Points: 25

Up
0
Down
But perform above steps only after taking backup of your table

:)

http://hashtagakash.wordpress.com/

Rajeshk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Macki on: 4/17/2013 [Member] Starter | Points: 25

Up
0
Down
Check My about steps on basis on Rajeshk secenario and tell d solution ..I've done that lot of times..

Regards
Macki

Rajeshk, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response