Login or Sign Up to become a member!

EXPERTS, INFORMATION, IDEAS & KNOWLEDGE

Social bookmarker Add this

Your profile

Search

January 2009
Mon Tue Wed Thu Fri Sat Sun
 << <   > >>
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  

XML Feeds

Authors

« Three Ways To Return All Rows That Contain Uppercase Characters OnlyCompound Operators Or How T-SQL Is Morphing Into VB Or C# »
The Data Management Journal

How to rename a column in a SQL Server table without using the designer

by SQLDenis


Permalink 23 Jun 2008 10:23 , Categories: Data Modelling & Design

If you have a table and you want to rename a column without using the designer, how can you do that?

First create this table

  1. CREATE TABLE TestColumnChange(id int)
  2. INSERT TestColumnChange VALUES(1)
  1. SELECT * FROM TestColumnChange

As you can see the select statement returns id as the column name. you can use ALTER table ALTER Column to change the dataype of a column but not the name.

Here is what we will do, execute the statement below

  1. EXEC sp_rename 'TestColumnChange.[id]', 'value', 'COLUMN'

Now do the select, you will see that the column name has changed

  1. SELECT * FROM TestColumnChange

That is it, very simple

Leave a comment »Send a trackback » 338 views

Trackback address for this post

Trackback URL (right click and copy shortcut/link location)

No feedback yet

Leave a comment


Your email address will not be revealed on this site.

Your URL will be displayed.
PoorExcellent
(Line breaks become <br />)
(Name, email & website)
(Allow users to contact you through a message form (your email will not be revealed.)