0

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.

2
  • 1
    Could share with us the structure of the tables,please? Commented Dec 15, 2019 at 15:35
  • 2
    you need to use "insert select" statement: insert into table1 select f1,f2,f3 from table2 Commented Dec 15, 2019 at 15:43

1 Answer 1

2

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
SELECT *
FROM dbo.Table2;

DROP TABLE dbo.Table2;

Now all your data is in one table, Table1.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.