T-SQL reference › INSERT SELECT
INSERT … SELECT in SQL Server
INSERT SELECT copies the result of a query into a table. Name both sides. SELECT * will break the day someone adds a column.
A working copy
INSERT INTO OrdersAudit (order_id, customer_id, total_amount, copied_at)
SELECT order_id, customer_id, total_amount, GETDATE()
FROM Orders
WHERE order_date >= CAST(GETDATE() AS date);
WorkSQL does not run inserts. At work, wrap a write in a transaction if you are still learning, and SELECT the output first without the INSERT.
Try it on Harbour & Co
Amy Nair (Finance Lead) needs this now: “Can I get a customer contact list? Just first name, last name and email.” Write the query, run it, send the results. Free.
Take the ticket →Learn it on a real ticket
Monday is free on WorkSQL. A colleague’s ticket lands, you write the T-SQL, we mark it. No videos. Five minutes.
Clock in free See Monday’s tickets