?
Solved

Update Column Data Type in SQL Server 2008R2

Posted on 2012-08-29
6
Medium Priority
?
876 Views
Last Modified: 2012-08-30
Hi, how do I update Column Data Type in SQL Server 2008R2 using MS SQL Server Management Studio?
The current data type is nvarchar(1), and need to change this to nvarchar(150). Need to change this without losing existing data.
0
Comment
Question by:kris_sk2012
6 Comments
 
LVL 25

Expert Comment

by:Lee Savidge
ID: 38346151
alter table alter column column_name nvarchar(150)
0
 
LVL 25

Expert Comment

by:Lee Savidge
ID: 38346155
replace table with your table name and then replace column_name with your column name. Do this in SQL Management Studio within the correct database.
0
 
LVL 5

Expert Comment

by:VIVEKANANDHAN_PERIASAMY
ID: 38346166
ALTER TABLE dbo.TableName
ALTER COLUMN Col_NAME NVARCHAR(150)
GO

sp_help 'Tablename'
GO
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
LVL 12

Expert Comment

by:Jared_S
ID: 38346188
Right click the table the field resides in and select "design", then just edit the data type.

You'll get an alert window, but you won't lose any data, but it's always a good idea to make a backup before altering the database.
0
 
LVL 9

Accepted Solution

by:
Vijaya Reddy Pinnapa Reddy earned 2000 total points
ID: 38346454
ALTER TABLE dbo.YourTable
   ALTER COLUMN YourColumnName nvarchar(150)

or
follow steps given in the site
http://msdn.microsoft.com/en-us/library/ms190259(v=sql.100).aspx
0
 
LVL 25

Expert Comment

by:Lee Savidge
ID: 38350660
Erm, isn't that what I posted in my comment about an hour before the accepted answer?

Indeed, isn't this also what VIVEKANANDHAN_PERIASAMY posted in their comment just under an hour before the accepted answer?

 Jared_S also posted an equally valid method using the interface rather than using code just a few minutes later way before the accepted anwer.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question