Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 alter table issue

Author  Topic 

pnpsql
Posting Yak Master

246 Posts

Posted - 2011-08-26 : 01:54:17
i have numeric column i altered it to varchar(20) , but i want to change it to varchar(10) . how can it be possible .




challenge everything

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-08-26 : 02:10:11
[code]ALTER TABLE ALTER COLUMN columnname varchar(10) NOT NULL[/code]
Add the red part only if its not nullable
make sure you dont have any data which is over 10 characters already present

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2011-08-26 : 02:13:17
Why did you in the first place change NUMERIC to varchar?
Did you have a problem with presentation issues?


N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

pnpsql
Posting Yak Master

246 Posts

Posted - 2011-08-26 : 02:18:23
i think u dont understand my problem. the problem is how to alter column
varchar(20) to varchar(10) , the sql server did't support this.



challenge everything
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-08-26 : 02:21:57
quote:
Originally posted by pnpsql

i think u dont understand my problem. the problem is how to alter column
varchar(20) to varchar(10) , the sql server did't support this.



challenge everything


it will support this using ALTER TABLE ALTER COLUMN
but question is why to do this

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

pnpsql
Posting Yak Master

246 Posts

Posted - 2011-08-26 : 02:25:37
please do not put question over this question...if u are intended to help then do this . the need of this is poc only

challenge everything
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-08-26 : 02:48:00
quote:
Originally posted by pnpsql

please do not put question over this question...if u are intended to help then do this . the need of this is poc only

challenge everything


do you really follow what is suggested?
we've already given you the suggestion
there's no reason why somebody should be doing this in normal case thats why we were trying to ask what prompted you to do this change


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2011-08-26 : 04:28:15
We ARE helping you by making you understand that altering a numeric column to varchar is a bad design choice, if the column still will store numeric values.
And besides, your tag line makes it perfectly safe for us to ask.
quote:
challenge everything


N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

pnpsql
Posting Yak Master

246 Posts

Posted - 2011-08-26 : 04:37:23
every time when i put my any type of query . i learn above the level i
expect with all of u. sorry if i hurt anyone by my rude comments.

back to my question:

i need to do this because there is some design reqirement that we can put both numeric and varchar type of data in that column.







challenge everything
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2011-08-26 : 04:59:38
Change the requirement!
You will be in tons of problems later (especially validation rules).
Why do you need to have both varchar data and numeric in same column?
Give a few examples of varchar data you want to store in the column, alongside numeric data.




N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2011-08-26 : 06:21:03
quote:
Originally posted by pnpsql

please do not put question over this question...if u are intended to help then do this . the need of this is poc only

challenge everything


Dude.

You get annoyed when someone challenges you about your approach. Yet your signature reads: "challenge everything"

Distinctly not cool.

Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page
   

- Advertisement -