1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[9447],{8411:(e,n,t)=>{(window.__NEXT_P=window.__NEXT_P||[]).push(["/learn/sql-insert",function(){return t(7033)}])},7033:(e,n,t)=>{"use strict";t.r(n),t.d(n,{default:()=>u});var s=t(5105),a=t(9358),i=t(976),r=t(3588),o=t(1189),l=t(2967),c=t(8101);let d=[{title:"Understanding INSERT",instruction:"\nSQL INSERT statements add new rows to database tables. Understanding proper insertion techniques is crucial for data management.\n\nKey Concepts:\n⢠Basic INSERT syntax\n⢠Column specifications\n⢠Value formatting\n⢠Default values\n⢠Constraints handling\n\nCommon Use Cases:\n⢠Adding new customers\n⢠Recording orders\n⢠Creating product entries\n⢠Storing user data\n⢠Logging events\n\nBest Practices:\n⢠Always specify columns\n⢠Validate data before insert\n⢠Handle unique constraints\n⢠Consider transactions\n⢠Document requirements\n\nExample Syntax:\n```sql\nINSERT INTO customers (\n name,\n email,\n created_at\n) VALUES (\n 'John Doe',\n '[email protected]',\n CURRENT_TIMESTAMP\n);\n```\n",hasEditor:!1},{title:"Basic Single Row Insert",instruction:"\nMaster the basic INSERT operation by adding a single row to a table.\n\nBusiness Scenario:\nAdd a new customer to the database.\n\nWrite a query that:\n⢠Inserts one customer\n⢠Specifies name and email\n⢠Uses current timestamp\n⢠Follows best practices\n⢠Maintains data quality\n\nRequirements:\n⢠Include all required fields\n⢠Format data correctly\n⢠Handle timestamps\n⢠Follow naming conventions\n⢠Consider constraints\n\nTips:\n⢠Check column names\n⢠Match data types\n⢠Use proper quotes\n⢠Consider NULL values\n⢠Validate the data\n",hasEditor:!0,initialQuery:"-- Add a new customer\n",solution:"INSERT INTO customers (name, email, created_at) VALUES ('Alice Johnson', '[email protected]', CURRENT_TIMESTAMP)",hint:"Specify columns explicitly and provide values in the correct order.",tables:["customers"]},{title:"Multiple Row Insert",instruction:"\nLearn to insert multiple rows efficiently in a single statement.\n\nBusiness Scenario:\nAdd several new products to inventory.\n\nWrite a query that:\n⢠Inserts multiple products\n⢠Sets names and prices\n⢠Includes categories\n⢠Uses single statement\n⢠Maintains consistency\n\nKey Concepts:\n⢠Bulk insert syntax\n⢠Value grouping\n⢠Data consistency\n⢠Performance benefits\n⢠Error handling\n\nTips:\n⢠Group values properly\n⢠Maintain column order\n⢠Check constraints\n⢠Consider performance\n⢠Validate all data\n",hasEditor:!0,initialQuery:"-- Add multiple products\n",solution:"INSERT INTO products (name, price, category_id) VALUES ('Laptop Pro', 1299.99, 1), ('Wireless Mouse', 29.99, 1), ('USB Cable', 9.99, 1)",hint:"Use multiple value sets separated by commas.",tables:["products"]},{title:"Insert with Default Values",instruction:"\nLearn to use default values and generated columns in INSERT statements.\n\nBusiness Scenario:\nCreate new orders with system-generated values.\n\nWrite a query that:\n⢠Creates new order\n⢠Uses default timestamps\n⢠Sets customer ID\n⢠Allows auto-increment\n⢠Handles defaults\n\nBest Practices:\n⢠Understand defaults\n⢠Document assumptions\n⢠Test edge cases\n⢠Verify results\n⢠Handle errors\n\nTips:\n⢠Check table structure\n⢠Know your defaults\n⢠Test thoroughly\n⢠Monitor results\n⢠Document behavior\n",hasEditor:!0,initialQuery:"-- Create new order with defaults\n",solution:"INSERT INTO orders (customer_id, product_id, quantity) VALUES (1, 1, 1)",hint:"Only specify required columns, let the system handle defaults.",tables:["orders"]},{title:"Insert from SELECT",instruction:"\nMaster inserting data from one table into another using SELECT statements.\n\nBusiness Scenario:\nCopy high-value customers to VIP table.\n\nWrite a query that:\n⢠Selects premium customers\n⢠Copies specific columns\n⢠Filters by criteria\n⢠Maintains data types\n⢠Ensures consistency\n\nAdvanced Concepts:\n⢠Subquery usage\n⢠Data transformation\n⢠Filtering criteria\n⢠Column mapping\n⢠Error handling\n\nTips:\n⢠Match column types\n⢠Verify data quality\n⢠Consider indexes\n⢠Test with samples\n⢠Document process\n",hasEditor:!0,initialQuery:"-- Copy premium customers to VIP table\n",solution:"INSERT INTO vip_customers (customer_id, name, total_spent) SELECT id, name, SUM(total) FROM customers JOIN orders ON customers.id = orders.customer_id GROUP BY id, name HAVING SUM(total) > 1000",hint:"Use INSERT INTO ... SELECT to copy and transform data.",tables:["customers","orders","vip_customers"]},{title:"Handling Duplicate Keys",instruction:"\nLearn strategies for handling unique constraint violations during inserts.\n\nBusiness Scenario:\nUpdate or ignore duplicate customer records.\n\nWrite a query that:\n⢠Handles duplicates\n⢠Updates existing data\n⢠Preserves uniqueness\n⢠Maintains integrity\n⢠Logs conflicts\n\nAdvanced Techniques:\n⢠IGNORE keyword\n⢠REPLACE syntax\n⢠ON CONFLICT\n⢠MERGE statements\n⢠Error handling\n\nBest Practices:\n⢠Plan conflict resolution\n⢠Document behavior\n⢠Test edge cases\n⢠Monitor performance\n⢠Maintain consistency\n",hasEditor:!0,initialQuery:"-- Insert or update customer\n",solution:"INSERT OR REPLACE INTO customers (id, name, email) VALUES (1, 'Updated Name', '[email protected]')",hint:"Use INSERT OR REPLACE to handle existing records.",tables:["customers"]}],u=()=>{let e=(0,a.useRouter)(),[n,t]=(0,c.useState)(new Set),u=e=>{t(n=>new Set(Array.from(n).concat(e)))},m=e=>{},p=n.size===d.filter(e=>e.hasEditor).length;return(0,s.jsx)(i.A,{metaTagsProps:{title:"SQL INSERT Tutorial: Master Data Insertion | Outerbase",description:"Learn SQL INSERT operations to add data to your database. Master single row inserts, bulk operations, and best practices with practical examples."},children:(0,s.jsx)(r.A,{lessonCompleted:p,children:(0,s.jsxs)("div",{className:"space-y-12",children:[(0,s.jsxs)("header",{className:"prose prose-neutral prose-invert max-w-none space-y-4",children:[(0,s.jsx)("h1",{children:"SQL INSERT"}),(0,s.jsx)("p",{className:"lead",children:"Master SQL INSERT operations to add data to your database. Learn about single row inserts, bulk operations, and best practices through hands-on examples."})]}),(0,s.jsxs)("nav",{className:"rounded-lg border border-white/10 bg-white/5 p-4",children:[(0,s.jsx)("h2",{className:"text-sm font-medium text-white/60",children:"Qu
1ick Navigation"}),(0,s.jsx)("ul",{className:"mt-2 space-y-1",children:d.map((e,n)=>(0,s.jsx)("li",{children:(0,s.jsx)("a",{href:"#".concat(e.title.toLowerCase().replace(/\s+/g,"-")),className:"text-sm text-white/80 hover:text-white",children:e.title})},n))})]}),(0,s.jsx)("div",{className:"space-y-16",children:d.map((e,n)=>(0,s.jsxs)("section",{id:e.title.toLowerCase().replace(/\s+/g,"-"),className:"scroll-mt-8",children:[(0,s.jsxs)("div",{className:"prose prose-neutral prose-invert max-w-none space-y-4",children:[(0,s.jsx)("h2",{children:e.title}),(0,s.jsx)(l.A,{content:e.instruction})]}),e.hasEditor&&(0,s.jsx)("div",{className:"mt-8 space-y-4",children:(0,s.jsx)(o.A,{initialQuery:e.initialQuery||"",tables:e.tables||[],onSuccess:()=>u(n),onError:m,expectedSolution:e.solution,hint:e.hint},n)})]},n))}),(0,s.jsxs)("section",{className:"flex justify-between border-t border-white/10 pt-8",children:[(0,s.jsx)("button",{onClick:()=>{e.push("/learn/sql-group-by")},className:"rounded-md bg-white/5 px-4 py-2 text-sm font-semibold text-white transition-all hover:bg-white/10",children:"â Previous: SQL Group By"}),(0,s.jsx)("button",{onClick:()=>{e.push("/learn/sql-update")},className:"rounded-md bg-white/90 px-4 py-2 text-sm font-semibold text-black transition-all hover:bg-white",children:"Next: SQL Update â"})]})]})})})}}},e=>{var n=n=>e(e.s=n);e.O(0,[3701,4192,5598,3870,801,4775,6752,5088,636,6593,8792],()=>n(8411)),_N_E=e.O()}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.