Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2003
    Posts
    44

    Unanswered: Altering column names?

    I have been looking in the SQL Server Help Files, but I cant seem to find the syntax to change the name of a column name..?

    Can it be done? if so, what is the syntax?

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    well, i guess you could do this:
    Code:
    alter table foo
    add column barnew  datatype etc.
    
    update table foo
    set barnew = bar
    
    update table foo
    drop column bar
    but why? i mean, you can change the name in any select statement:
    Code:
    select bar as barnew
      from foo
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Dec 2003
    Posts
    44
    I want to be able to change the names of columns because I am building an interface to an SQL Database.

    That code you gave me doesnt work, you dont use the word 'column' when adding a new column, you just use 'add' alone.

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    sorry, i do not always test out the syntax i suggest

    but at least i got across the idea of the approach to use

    you're welcome
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    Join Date
    Jul 2003
    Location
    The Dark Planet
    Posts
    1,401
    Well .. i think sp_rename works on columnt too ... need to check that out ..


    Code:
    create table myTab (mycol int)
    go
    sp_rename 'mytab.mycol' ,'mytab.mycol1'
    go
    select mycol1 from myTab
    go
    Seems to work
    Get yourself a copy of the The Holy Book

    order has no physical Brett in The meaning of a Kaiser . -database data

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •