# INSERT ने sample data जोडा

Source: https://ravindrabagale.com/mr/cyber/part-05/ch10-mysql-part-1-install-create-insert-and-select/10-4-inserting-data.html
Language: mr (Marathi with English technical terms)

पुढच्या SELECT आणि JOIN exercises साठी हा sample dataset वापरू. Names, emails, cities आणि values मूळ course प्रमाणे आहेत. रिकाम्या नवीन tables मध्ये एकदाच insert केल्यावर अपेक्षित IDs मिळतील.

INSERT INTO students (name, email, city, age, fees_paid, joined_on) VALUES
 ('Ravindra Bagale', 'ravindra@example.com', 'Pune',         NULL, 15000, '2026-01-05'),
 ('Shraddha Bagale', 'shraddha@example.com', 'Pune',           29, 15000, '2026-01-05'),
 ('Ruhi Bagale',     'ruhi@example.com',     'Nashik',         21, 12000, '2026-02-10'),
 ('Shahrukh',        'shahrukh@example.com', 'Nagpur',         24,  8000, '2026-02-15'),
 ('Amir',            'amir@example.com',     'Kolhapur',       26, 15000, '2026-03-01'),
 ('Salman',          'salman@example.com',   'Solapur',        23,     0, '2026-03-03'),
 ('Zoya',            'zoya@example.com',     'Sambhaji Nagar', 22, 10000, '2026-03-20'),
 ('Ravina',          'ravina@example.com',   'Nagpur',         25, 12000, '2026-04-02'),
 ('Raja',            NULL,                   'Nashik',         20,  5000, '2026-04-11'),
 ('Rani',            'rani@example.com',     'Pune',           27, 15000, '2026-04-18');

INSERT INTO courses (course_name, duration_wk) VALUES
 ('Networking', 4), ('Linux', 6), ('AWS', 8), ('Ethical Hacking', 10), ('SOC Analyst', 6), ('Cloud Security', 6);

INSERT INTO enrollments (student_id, course_id, score) VALUES
 (1,1,92),(1,4,88),(2,2,79),(3,1,65),(3,2,71),(4,4,58),(5,3,84),
 (6,1,45),(7,5,90),(8,4,76),(8,5,81),(10,3,67);

SELECT COUNT(*) FROM students;     -- 10

Students table मध्ये 10 rows. Raja (student 9) ला enrollment नाही; Linux course ला दोन students आणि Cloud Security course ला एकही enrollment नाही. Ravindra चं age मुद्दाम NULL आणि Raja चं email NULL आहे. पुढे NULL/JOIN examples साठी हे उपयोगी पडेल.

Script पुन्हा चालवल्यास unique email errors किंवा duplicate data येऊ शकतो; auto-increment IDs आधी वापरलेले असतील तर enrollment IDs अपेक्षेप्रमाणे जुळणार नाहीत. म्हणून fresh lab आणि row counts तपासा.

Security मध्ये उपयोग

User input असलेला INSERT string जोडून बनवू नका. Input मुळे quotes/query structure बदलू शकते आणि SQL injection होऊ शकतो. Chapter 9.7 प्रमाणे placeholders आणि prepared statements वापरा.

Practice

Sample dataset insert करून COUNT तपासा. मग स्वतःची एक sample student row आणि तुमच्या आवडीचा एक course जोडा. पुढच्या source outputs मूळ 10-row dataset चे आहेत; नव्या rows मुळे counts बदलतील.

रवींद्र बागले यांची tip

INSERT मध्ये column names स्पष्ट लिहा. Schema बदलल्यावर position-based INSERT तुटू शकतो. Text single quotes मध्ये, numbers योग्य numeric format मध्ये आणि missing value साठी SQL NULL वापरा.
