| Author |
Topic |
|
REDDY
Starting Member
43 Posts |
Posted - 2003-11-04 : 17:19:30
|
| For some reason I need to change the column positions of a big table with 1 million rows and 128 columns on production server.What is the best way to do this??I tried with EM it is taking too long time( I guess it is dropping the table and recreating).IS it advisable to update 'colid' of syscolumns table to accomplish the above task??RegardsReddy |
|
|
Merkin
Funky Drop Bear Fearing SQL Dude!
4970 Posts |
Posted - 2003-11-04 : 17:35:19
|
| NO DO NOT PLAY WITH SYSTABLES!!!!If you look at what EM is doing, you will find it :Creates an identical tableCopies all your data inDumps all the constraintsDrops and recreates the tableCopies the data back inRecreates the constraintsSO, you can let EM do it, or write that script yourself.Two questions :1. Why do you have 128 columns ? 2. Why does column order matter ? You can order in a select statement.Both of those things usually point to a design problem.Damian |
 |
|
|
REDDY
Starting Member
43 Posts |
Posted - 2003-11-04 : 18:16:33
|
| Thank you very much for your suggestion..Regarding 128 columns on the table ,I have no answer,since this table exists before I joined this company and Lot of applications are pointing to this tableso at present no plans of denormalising the table,About the column order,since we have too many columns(128) it is becoming difficultfor us to locate the column names while developing the applications,if they aregrouped together it will be easy for developers to locate them in EM.Any way I will go ahead with EMRegardsReddy |
 |
|
|
byrmol
Shed Building SQL Farmer
1591 Posts |
Posted - 2003-11-04 : 18:22:15
|
| Reddy,Why not create a VIEW?DavidM"SQL-3 is an abomination.." |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2003-11-04 : 18:28:59
|
| REDDY, EM is doing the steps that Merkin mentioned. That is how you change column positions. So yes it will be slow on large tables. DavidM's solution is best if you can not afford the slowness in production. Just put the columns in the correct order in the view and it'll look like you changed the position. Of course developers would need to call the view and not the table then.Tara |
 |
|
|
REDDY
Starting Member
43 Posts |
Posted - 2003-11-04 : 18:32:16
|
| David, How does it solve the purpose??could you please explain??thanksReddy |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2003-11-04 : 18:34:17
|
| REDDY, here is why:Here is your table:CREATE TABLE Table1(ColumnA INT NOT NULL,ColumnB INT NOT NULL,ColumnC INT NOT NULL,ColumnD INT NOT NULL,)Now let's say that you want ColumnD to come right after ColumnA, then:CREATE VIEW Table1_viewASSELECT ColumnA, ColumnD, ColumnB, ColumnCFROM Table1Tara |
 |
|
|
byrmol
Shed Building SQL Farmer
1591 Posts |
Posted - 2003-11-04 : 18:35:48
|
| Reddy,As Tara said, you put the columns in the correct order in the VIEW and reference the view..There should be no performace impactDavidM"SQL-3 is an abomination.." |
 |
|
|
REDDY
Starting Member
43 Posts |
Posted - 2003-11-04 : 18:50:10
|
| Thank you very much David and Tara...View should solve the probelm.. only disadvantage I could see is to update the view, if there is any column added/modified to the base table.But that can be taken care very easily.once again thanks a lot for quick responses.RegardsReddy |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2003-11-05 : 01:03:36
|
| If the only problem is that the developers have problems understanding the columns then create a data dictionary for them. This can just be a table with the columns and a description and an ordering field which they can query.Sounds like your system might need something like this anyway.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
|