Saturday, February 25, 2012

column position sql table

There are about 500 tables in one particular datbase. There areforeign keys set on most of the tables. I want to change the positionof the primary key column in all those tables. How can I do thatprogramatically?

What do you mean by "position" of the PK column?

|||

PK = primary key

|||

Let me rephrase my question:

What do you mean by"position" of the PK column?

|||

Hi dilbert1947,

Based on my understanding, if you mean "the column sequence number" for "the position of the primary key column", then i think there is nothing you have to worry about. In my opinion, changing the column sequence of your primary key won't affect anything in your database schema.

Hope my suggestion can help

|||

Ok let me put it this way. I had to add a primary key column (programmatically) to all the tables in a database. Now when you right click and view the table, you see the newly added primary key column as the right most column. After the primary key column was added, many foreign keys were also added in many of the tables. Now one way to change the column "position" is to manually right click on each table and click modify and then manually move the column to the top, so that every time you view the table, the primary key column appears on the left. Myself being a lazy person, I'd lprefer to write code that would do this in all the tables rather than manually modifying all the tables.

I hope that makes things clear.

|||

Do it manually in one of the tables. Then before you save the changes, click the button that says "Generate change SQL file" or something like that. Then read the file and see what the tool was going to execute.

No comments:

Post a Comment