Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Query to change the datatype of column in sql server

Jul 8, 2012
Introduction:

In this article I will explain how to change or rename datatype of column in SQL server.

Description:

In previous post I explained how to alter or modify or delete or change already existing column in datatable in SQL Server and many articles relating to SQL Server. Now I will explain how to rename or change datatype of column name or table name in SQL Server.

Syntax to modify existing column datatype in table

If we want to modify existing column datatype from data table that syntax will be like this


ALTER TABLE Table_Name ALTER COLUMN COLUMN_NAME DATATYPE
Ex:


ALTER TABLE emp_table ALTER COLUMN Manager_Name nvarchar(max)
From the above query declaration I changed “Manager_Name” column datatype from VARCHAR(50) to nvarchar(max)

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

3 comments :

Alex Peta said...

Does this work even if the column is populated with data? I dont think so. The right way to do this is to create a new aux column, copy the original data there, empty the target column with nulls, alter it, and the copy back data from aux to target.

Edi Prakoso said...

hai suresh, what is the different between nvarchar and varchar?

Suresh Dasari said...

@Edi Prakoso....
check this post
http://www.aspdotnet-suresh.com/2012/07/difference-between-char-varchar-and.html

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.