Yanıt how to rename table name in sql?

  • 13 Haziran 2008 Cuma 09:19
     
     
    how to rename table name in sql?

    i trid as like

    rename table table_name to new_table_name


    but this raises an error

Tüm Yanıtlar

  • 13 Haziran 2008 Cuma 17:21
     
     Yanıt

    Try sp_rename:

     

    Code Snippet

    sp_rename 'old_table_name', new_table_name'

     

     

  • 29 Haziran 2008 Pazar 17:34
     
     Önerilen Yanıt

    Once table name is renamed, please ensure you recompile your objects (SP, Trigger, View, Function), the ones that are using this Table, with the new name Smile

  • 19 Mart 2009 Perşembe 20:25
     
     
    hi friend u can rename ur table from left side object explorer
    first of all click on database and expand this then click on ur database name so u can c ur table name , after right click on that table name whose u want to rename
    and click on rename option from ur right click pop menu
    ok take care bye
  • 15 Nisan 2009 Çarşamba 07:34
     
     
    I guess your answer is useless
  • 05 Nisan 2011 Salı 18:44
     
     Önerilen Yanıt

    HI JANARDHANA,

     

    IT'S VERY  SIMPLE TO RENAME THE TABLE SEE BELOW

     

    SP_RENAME 'EXIST TABLE NAME ','NEW TABLE NAME' 

    EG

    SP_RENAME 'EMP','EMPLOYEE'

     

  • 27 Eylül 2011 Salı 11:04
     
     
    This worked. Thank you very much.
  • 02 Aralık 2011 Cuma 05:34
     
     

    I see your answer Mr. bulandraza. But i am extremely sorry that there is no option to rename the way you explaining. 

    Please first do practical on the answers and then write. You are guiding wrong to the fresher and answer needer.

    Atul Dhiman

     

     

  • 02 Aralık 2011 Cuma 05:59
     
      Kod İçerir

    I am explaining the answer in steps by steps so it is very easy to understand for freshers.

    1. First select the the table you want to rename in Server Explorer.
    2. Right click with mouse on the the table and then select New Query.
    3. It will show all tables in the small window and select the table you want to rename and then close.
    4. A query is written in the bottom. Delete it and just write your required query.

     

    Delete the select query and write sp_rename 'oldtablename','newtablename'

    By taking the example of upper table the query would be

    sp_rename 'tb_adminlogin','adminlogin'
    


    Hope this answer help all the seekers for this question.

    Atul Dhiman

  • 18 Temmuz 2012 Çarşamba 05:39
     
     

    Hi,

    Re-Naming Column:

    USE AdventureWorks
    GO
    sp_RENAME 'Table_First.Name', 'NameChange' , 'COLUMN'
    GO

    Re-Naming Table:

    sp_RENAME 'Table_First', 'Table_Last'
    GO


    Thanks Shiven:) If Answer is Helpful, Please Vote

  • 02 Ağustos 2012 Perşembe 18:07
     
     
    Actually, Bulandraza's option is valid.  I use it all the time.
    • Düzenleyen vnns 02 Ağustos 2012 Perşembe 18:09
    •