I have completely same defined 2 tables : t2 and t1.
t2 has 1000 rows and t1 is totally empty.
How can I SELECT top 500 rows from t2 and INSERT them to t1?
It produces a cartesian product, so the number of rows in the result set will be the number of rows from table1 multiplied by number of rows from table2 (assuming there are no constraints in the WHERE clause). It effectively pairs each row from table1 with a row coming from table2 .
Select all the cells where you want to enter the same data Put the cursor to the first cell in the column (or the second one if your Table has headers), then press Shift+Ctrl+End to go to the end of your table, hold Shift and press the Left key repeatedly until only the needed column gets selected.
You can use the SELECT and INSERT statements to copy rows from one SQL table to another. This is the basic syntax: INSERT INTO table_name1 (columns) SELECT columns FROM table_name2; In this example, I have created a cats table with three rows in it with the same column names as the dogs table.
I'll use "emptyTable" and "populatedTable" because the questions is confusing
Important TOP
without an ORDER BY gives 500 arbitrary rows. There is never an implied or natural order to a table
INSERT INTO emptyTable
SELECT TOP 500 *
FROM populatedTable
ORDER BY What -- need this to define TOP 500
The lack of column list here is usually defined as bad practice but works only if
Edit:
ORDER BY is required to guarantee row order. See these. It's also in the ANSI standard
Something like this:
INSERT INTO t1
SELECT TOP 500 * FROM t2
You select the top 500, and insert them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With