HOW TO ALTER /RENAME TABLE NAME WITH TSQL CODE?

  • HOW DO I CHANGE THE TABLE NAME WITH TSQL CODE?

    THANKS

  • sp_rename

  • To rename a table

    Exec sp_Rename 'schema.original_table_name','new_table_name','object'

    Go

    To rename a field

    Exec sp_Rename 'schema.table_name.original_field_name','new_field_name','column'

    Go

    Note: The rule requiring [brackets] around partially invalid names (i.e. - dbo.[1_Table_Name]) should be used in the original name section of the statement, but DO NOT use it in the new name section of the statement.

    Example:

    Exec sp_Rename 'dbo.[1_table_name].[2_original_field_name]','3_new_field_name','column'

    [font="Arial"]“Any fool can know. The point is to understand.”
    - Albert Einstein

    "DOH!"
    - Homer Simpson[/font]

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply