6

I uploaded some tables to SQL Server Management Studio. Upon inspecting the tables I've found that the column headers area actually values. Is there any way to bump the headers down into a new row and to create new column headers, or will I have to re-upload all of the tables and remember to select the 'has header' option?

Thanks.

  • 1
    from what source you uploaded the tables? Excel or CSV? – Rajesh Ranjan Jul 22 at 15:27
  • Sorry, I should have mentioned that. Excel, it was one sheet with several tabs. – CharlesD Jul 22 at 15:39
6

Probably the least complicated option would be to select all your data into a new table with the correct column names, filtering out the row of values containing the header values. From there, you can drop the malformed table, and rename the new one.

Example:

CREATE TABLE dbo.wrongo(wrong INT, [column] INT, names INT);
CREATE TABLE dbo.righto(correct INT, [column] INT, names INT);

INSERT dbo.righto ( correct, [column], names )
SELECT wrong, [column], names
FROM dbo.wrongo
WHERE wrongo.wrong <> 'column name'; --this will throw an error, but you get the idea.

DROP TABLE dbo.wrongo;

EXEC sp_rename 'dbo.righto', 'wrongo', 'OBJECT';
0

There are two ways you can avoid having values as columns name while loading data from excel source.

  1. Create the table in the database using the CREATE TABLE statement and then upload data using DTS.
  2. Mention column names as the first record in the excel sheet and upload it.

There are other ways too, but these are easier steps.

Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.