Problem solve Get help with specific problems with your technologies, process and projects.

Adding columns and determining row size

Development expert Greg Low explains how to insert new columns and assess table row sizes.

1. How do I add a column between two columns in a table in SQL Server?
2. How do I get the row size of the table?
For #1, I wish I could tell you an easy way to do that. Knowing that Enterprise Manager does that, if you fire up a Profiler session and watch what it does, it creates a temporary table with the new column structure, INSERT..SELECT's all the data into it, drops the old table and renames the temporary one to the original name.

For #2, as long as you don't have BLOB columns, you'd want something along the lines of:

SELECT SUM(length)
FROM syscolumns
WHERE id = (SELECT id FROM sysobjects
WHERE xtype = 'U'
AND name = 'TableName')

View questions and answers from all of our SQL Server experts here.

Dig Deeper on SQL Server Database Modeling and Design

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.