alter table name error and table column

  • ----change In the name of Table 5 Table 6

    Use test

    GO

    ALTER TABLE NAME tablo5 RENAME TO tablo6;

    GO

    but error messages::

    Msg 102, Level 15, State 1, Line 1

    Incorrect syntax near 'tablo5'.

    ------------------

    ------------------

    ----tablo4 d1 ==> d11 change.

    Use test

    GO

    ALTER TABLE tablo4 RENAME COLUMN d1 TO d11;

    GO

    error messages::

    Msg 102, Level 15, State 1, Line 1

    Incorrect syntax near 'RENAME'

    Edit/Delete Message

  • sql renames tables via a stored procedure..the syntax you are using is appropriate for Oracle only, i think.

    sp_rename 'OriginalTableName','NewTableName'

    --or

    -- if you have two items with the same name but different schemas,

    --identify the schema specifically

    sp_rename 'dbo.OriginalTableName','NewTableName'

    sp_rename 'Orange.OriginalTableName','NewTableName'

    --above renamed to Orange.NewTableName

    --renaming a column

    sp_rename 'dbo.OriginalTableName.Entitynm','EntityName','column'

    johnny1walker (3/14/2012)


    ----change In the name of Table 5 Table 6

    Use test

    GO

    ALTER TABLE NAME tablo5 RENAME TO tablo6;

    GO

    but error messages::

    Msg 102, Level 15, State 1, Line 1

    Incorrect syntax near 'tablo5'.

    ------------------

    ------------------

    ----tablo4 d1 ==> d11 change.

    Use test

    GO

    ALTER TABLE tablo4 RENAME COLUMN d1 TO d11;

    GO

    error messages::

    Msg 102, Level 15, State 1, Line 1

    Incorrect syntax near 'RENAME'

    Edit/Delete Message

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • thank you very much.

    renaming table name success 🙂

    but

    --i dont renaming a column

    Use test

    GO

    sp_rename 'tablo4','d1','d11'

    GO

    just started to sql

    Can you write code

    thanks.

  • this link will help you, in the examples section it details on renaming a column

  • For renaming a column the syntax is:

    EXEC sp_rename 'Table.OldColumnName', 'NewColumnName', 'COLUMN'

    Andy

    ==========================================================================================================================
    A computer lets you make more mistakes faster than any invention in human history - with the possible exceptions of handguns and tequila. Mitch Ratcliffe

Viewing 5 posts - 1 through 4 (of 4 total)

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