Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / General / Data Warehousing / November 2005

Tip: Looking for answers? Try searching our database.

Rearrange fields alphabetically

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
zknezic - 01 Nov 2005 18:16 GMT
Hi,
I am trying to alter a large table (with 100+ fields) so the fields are
ordered alphabetically. Is there a quicker and smarter way of doing this,
other then manual one-by-one?
Thanks,

Zoran
arbert - 05 Nov 2005 19:05 GMT
> *Hi,
> I am trying to alter a large table (with 100+ fields) so the fields
[quoted text clipped - 5 lines]
>
> Zoran *

Not really.  Either way, it's going to involve a lot of data movement
on the backend.

Is it possible for you to just put a view on the front-end and order
the columns there and just allow your end users to use the view?

--
arbert
------------------------------------------------------------------------

zknezic - 08 Nov 2005 16:32 GMT
That is a possibility, it is just a matter of breaking a habit of those who
are using the table regularly. As they say "If there is a will, there is a
way"...

> > *Hi,
> > I am trying to alter a large table (with 100+ fields) so the fields
[quoted text clipped - 18 lines]
> ------------------------------------------------------------------------
>  
Adam Machanic - 05 Nov 2005 20:48 GMT
There is no supported method in SQL Server of moving columns in a table
except by dropping and re-creating the column.  But you certainly don't have
to do it one-by-one...

Let's say we had the following table:

CREATE TABLE out_of_order
(
 ColZ INT,
 ColY INT,
 ColX INT
)

We could create a new table with all of the same columns, in the right
order:

CREATE TABLE in_order
(
 ColX INT,
 ColY INT,
 ColZ INT
)

... and then INSERT all of the data from the other table:

INSERT in_order (ColX, ColY, ColZ)
SELECT ColX, ColY, ColZ
FROM out_of_order

... and then it's a simple matter of dropping the old table and re-naming
the new one:

DROP TABLE out_of_order

sp_rename 'in_order', 'out_of_order', 'table'

Signature

Adam Machanic
Pro SQL Server 2005, available now
www.apress.com/book/bookDisplay.html?bID=457
--

> Hi,
> I am trying to alter a large table (with 100+ fields) so the fields are
[quoted text clipped - 3 lines]
>
> Zoran
zknezic - 07 Nov 2005 17:51 GMT
Thanks Adam,
At some point I started contemplating the idea of updating syscolumns table
(changing colorder). Firstly, modifying this table was not allowed by
default. Secondly, it appears that this could be a messy job. I'll stick with
your suggestion, clean and simple...

Thank you,

zknezic

> There is no supported method in SQL Server of moving columns in a table
> except by dropping and re-creating the column.  But you certainly don't have
[quoted text clipped - 39 lines]
> >
> > Zoran
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.