Home » excel » excel – SQL Server: adding rows/tables with the same columns

excel – SQL Server: adding rows/tables with the same columns

Posted by: admin May 14, 2020 Leave a comment


I have two tables in SQL Server and both of those tables have the same headers, which means its the same columns, but since I added them from Excel, it means that I was not able to import them as one table, since it is more then 1 million rows.

So now I have one table with a bit less than a million rows and one with like 400000 rows and actually it should be one table, but Excel only allows around one million.

I have them both imported into SQL Server and actually I really want them to be both in one table like union.

The question is how to do it.

I just want to put one of them below the other since it is exactly the same column header.

How to&Answers:

What you should have done was import the first sheet, and create the table at the same time, and then import the second sheet into the existing table, in a separate import process. Or, if you were using SSIS, you could have used a Union Data Transformation to “combine” the 2 datasets into one, and then insert all the data into a single table.

You can, however, easily get the data into one table. Assuming you want to retain Table1 and that Table1 and Table2 do indeed have the same definitions (and don’t have IDENTITY columns) you can just do the following:

INSERT INTO dbo.Table1
FROM dbo.Table2;

DROP TABLE dbo.Table2;

Now all your data is in one table, Table1.

<a href="https://exceptionshub.com/category/sql-server”>More Answers>