Change table and fieldnames

  • I need to prefix an underscore to all the tablenames and fieldnames in an SQL2005 database. Can I create a script that does this for me? Please help!

  • jaguarxj12l (2/27/2008)


    I need to prefix an underscore to all the tablenames and fieldnames in an SQL2005 database. Can I create a script that does this for me? Please help!

    If you want the references to be updated as well, you could do one of the following:

    1: use sp_rename to rename the tables and fields; go through all the procedures,... in sys.sql_modules, and find the ones that reference the renamed objects, update these referencing procedures, views, ...

    2: alternatively you can use SQL Refactor (Disclaimer: this is a tool by a company I work for), and use smart rename (which renames your object, and the references), but it will not rename the columns.

    3: script the database schema, replace the names in the script, build it, and migrate the data.

    Regards,

    Andras


    Andras Belokosztolszki, MCPD, PhD
    GoldenGate Software

  • I got it solved!

    I had the original database scripted into a create script, had some Find and Replace actions executed, ran the script and got myself a new database. The only thing left is to transfer the data.

  • jaguarxj12l (2/27/2008)


    I got it solved!

    I had the original database scripted into a create script, had some Find and Replace actions executed, ran the script and got myself a new database. The only thing left is to transfer the data.

    And test it to make sure that all the stored procedures, views, ... still work as expected 🙂

    Regards,

    Andras


    Andras Belokosztolszki, MCPD, PhD
    GoldenGate Software

  • Unless you have a business definition don't start creating table with _ always have names that are with the tables function. so that its easy to work on that.

    Cheers,
    Sugeshkumar Rajendran
    SQL Server MVP
    http://sugeshkr.blogspot.com

  • I got no stored procedures and\or views stored in SQL, they are all stored in a different database. We only use SQL to accommodate the data.

    BUT! ... thanks for the tip!

  • I am terribly sorry, Sugesh ... but I don't understand one little bit what you mean to say. Could you please be a little bit more clear?

Viewing 7 posts - 1 through 6 (of 6 total)

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