SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 alter table issue
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

pnpsql
Posting Yak Master

India
241 Posts

Posted - 08/26/2011 :  01:54:17  Show Profile  Reply with Quote
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

India
47023 Posts

Posted - 08/26/2011 :  02:10:11  Show Profile  Reply with Quote
ALTER TABLE ALTER COLUMN columnname varchar(10) NOT NULL

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/


Edited by - visakh16 on 08/26/2011 02:11:25
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
29138 Posts

Posted - 08/26/2011 :  02:13:17  Show Profile  Visit SwePeso's Homepage  Reply with Quote
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

India
241 Posts

Posted - 08/26/2011 :  02:18:23  Show Profile  Reply with Quote
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

India
47023 Posts

Posted - 08/26/2011 :  02:21:57  Show Profile  Reply with Quote
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

India
241 Posts

Posted - 08/26/2011 :  02:25:37  Show Profile  Reply with Quote
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

India
47023 Posts

Posted - 08/26/2011 :  02:48:00  Show Profile  Reply with Quote
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

Sweden
29138 Posts

Posted - 08/26/2011 :  04:28:15  Show Profile  Visit SwePeso's Homepage  Reply with Quote
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"

Edited by - SwePeso on 08/26/2011 04:28:34
Go to Top of Page

pnpsql
Posting Yak Master

India
241 Posts

Posted - 08/26/2011 :  04:37:23  Show Profile  Reply with Quote
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

Sweden
29138 Posts

Posted - 08/26/2011 :  04:59:38  Show Profile  Visit SwePeso's Homepage  Reply with Quote
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
Flowing Fount of Yak Knowledge

United Kingdom
3425 Posts

Posted - 08/26/2011 :  06:21:03  Show Profile  Visit Transact Charlie's Homepage  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.11 seconds. Powered By: Snitz Forums 2000