SQL Data Manipulation Commands

Commands used to insert, change and remove data within a table.

SQL Data Manipulation Commands

SQL Data Manipulation Commands का उपयोग database में stored data को insert, modify, delete और retrieve करने के लिए किया जाता है। इन commands को सामान्यतः Data Manipulation Language (DML) के अंतर्गत रखा जाता है।

DML: Data Manipulation Language
Main Commands: INSERT, UPDATE, DELETE

What is Data Manipulation Language?

Data Manipulation Language (DML) SQL commands का एक समूह है जिसका उपयोग database tables में मौजूद records के साथ काम करने के लिए किया जाता है। DML की सहायता से हम नए records जोड़ सकते हैं, existing records को बदल सकते हैं और unwanted records को delete कर सकते हैं।

Database में stored data को manipulate करने के लिए मुख्य DML commands हैं:

  • INSERT – नए records जोड़ने के लिए
  • UPDATE – existing records को modify करने के लिए
  • DELETE – records को हटाने के लिए

Example Table

नीचे दिए गए Student table को DML commands को समझने के लिए उपयोग करेंगे:

RollNo Name Class Marks
101 Rahul 12 85
102 Priya 12 91
103 Aman 12 78

INSERT Command

INSERT command का उपयोग table में नया record या records जोड़ने के लिए किया जाता है।

Inserting a Complete Record

यदि table के सभी columns में values insert करनी हों, तो column names को लिखे बिना भी INSERT command का उपयोग किया जा सकता है। Values का क्रम table के columns के क्रम के अनुसार होना चाहिए।

INSERT INTO Student
VALUES (104, 'Neha', 12, 95);
Output:
1 row inserted successfully.

अब Student table में Neha का record भी शामिल हो जाएगा।

Inserting Values into Specific Columns

केवल selected columns में values insert करने के लिए column names specify किए जा सकते हैं।

INSERT INTO Student (RollNo, Name, Marks)
VALUES (105, 'Ravi', 88);
Output:
1 row inserted successfully.

इस उदाहरण में Class column के लिए value नहीं दी गई है। यदि उस column की कोई default value नहीं है और वह NOT NULL है, तो insertion सफल नहीं होगा।

Inserting Multiple Records

एक ही INSERT statement से एक से अधिक records भी add किए जा सकते हैं।

INSERT INTO Student (RollNo, Name, Class, Marks)
VALUES
(106, 'Karan', 12, 82),
(107, 'Pooja', 12, 89);
Output:
2 rows inserted successfully.

INSERT Syntax

INSERT INTO table_name
(column1, column2, column3)
VALUES
(value1, value2, value3);

UPDATE Command

UPDATE command का उपयोग table में पहले से मौजूद records की values को modify करने के लिए किया जाता है।

उदाहरण के लिए RollNo 103 वाले student के marks को 78 से 84 करना है:

UPDATE Student
SET Marks = 84
WHERE RollNo = 103;
Output:
1 row updated successfully.

अब RollNo 103 के student के marks 84 हो जाएंगे।

Updating Multiple Columns

एक ही UPDATE command से एक से अधिक columns की values बदली जा सकती हैं।

UPDATE Student
SET Class = 12, Marks = 90
WHERE RollNo = 103;
Output:
1 row updated successfully.

Updating Multiple Rows

यदि WHERE condition एक से अधिक records पर लागू होती है, तो उन सभी matching records को update किया जा सकता है।

UPDATE Student
SET Marks = Marks + 5
WHERE Class = 12;
Output:
All matching Class 12 records updated successfully.

यह command Class 12 के सभी students के marks में 5 जोड़ देगी।

UPDATE Syntax

UPDATE table_name
SET column1 = value1,
    column2 = value2
WHERE condition;
Important: UPDATE command में WHERE clause न देने पर table की सभी rows update हो सकती हैं। इसलिए UPDATE का उपयोग करते समय WHERE condition को ध्यानपूर्वक लिखना चाहिए।

DELETE Command

DELETE command का उपयोग table से records को remove करने के लिए किया जाता है। WHERE clause की सहायता से specific records delete किए जा सकते हैं।

उदाहरण के लिए RollNo 103 वाले student को delete करना है:

DELETE FROM Student
WHERE RollNo = 103;
Output:
1 row deleted successfully.

Deleting Multiple Records

यदि WHERE condition कई records पर लागू होती है, तो सभी matching records delete हो सकते हैं।

DELETE FROM Student
WHERE Marks < 80;
Output:
All students with Marks less than 80 deleted.

Deleting All Records

यदि DELETE command में WHERE clause नहीं दिया जाता है, तो table की सभी rows delete हो सकती हैं। Table की structure बनी रहती है।

DELETE FROM Student;
Output:
All records deleted from Student table.
Important: DELETE FROM table_name; में WHERE clause नहीं होने के कारण table की सभी rows delete हो सकती हैं। इस command को सावधानी से उपयोग करना चाहिए।

DELETE Syntax

DELETE FROM table_name
WHERE condition;

INSERT, UPDATE and DELETE

Command Purpose Example
INSERT नए records जोड़ना INSERT INTO Student VALUES (...)
UPDATE Existing records modify करना UPDATE Student SET Marks = 90 WHERE RollNo = 101
DELETE Records remove करना DELETE FROM Student WHERE RollNo = 101

DML vs DDL

DML और DDL दोनों SQL की महत्वपूर्ण command categories हैं, लेकिन दोनों का purpose अलग होता है। DDL database objects की structure पर काम करता है, जबकि DML stored records पर काम करता है।

Feature DDL DML
Full Form Data Definition Language Data Manipulation Language
Works on Database structure Stored data
Main Commands CREATE, ALTER, DROP, TRUNCATE INSERT, UPDATE, DELETE
Purpose Objects create/modify/remove करना Records insert/modify/delete करना

Role of WHERE Clause in DML

WHERE clause का उपयोग किसी condition के आधार पर specific records को identify करने के लिए किया जाता है। यह विशेष रूप से UPDATE और DELETE commands में बहुत महत्वपूर्ण है।

उदाहरण:

UPDATE Student
SET Marks = 95
WHERE RollNo = 102;
Output:
Marks of RollNo 102 updated to 95.

यह केवल RollNo 102 वाले record को update करेगा।

DML Commands with Example

मान लीजिए Student table में निम्न records हैं:

RollNo Name Marks
101 Rahul 85
102 Priya 91

एक नया student add करने के लिए:

INSERT INTO Student
VALUES (103, 'Aman', 12, 78);
Output:
1 row inserted successfully.

अब Aman के marks को 82 करने के लिए:

UPDATE Student
SET Marks = 82
WHERE RollNo = 103;
Output:
1 row updated successfully.

यदि Aman का record delete करना हो:

DELETE FROM Student
WHERE RollNo = 103;
Output:
1 row deleted successfully.

DML and Transaction Control

कुछ database systems में DML operations transaction के context में किए जाते हैं। Transaction को control करने के लिए COMMIT और ROLLBACK जैसे commands उपयोग किए जाते हैं। ये commands सामान्यतः Transaction Control Language (TCL) से संबंधित मानी जाती हैं, DML का हिस्सा नहीं।

Command Category Purpose
INSERT DML New record add करना
UPDATE DML Existing record modify करना
DELETE DML Record remove करना
COMMIT TCL Transaction changes को permanently save करना
ROLLBACK TCL Transaction changes को वापस करना

Important Points

  • DML का full form Data Manipulation Language है।
  • DML का उपयोग table में stored data को manipulate करने के लिए किया जाता है।
  • INSERT नए records जोड़ता है।
  • UPDATE existing records की values बदलता है।
  • DELETE records को remove करता है।
  • UPDATE और DELETE में WHERE clause specific records को target करने में मदद करता है।
  • WHERE clause के बिना UPDATE table की सभी rows को modify कर सकता है।
  • WHERE clause के बिना DELETE table की सभी rows को remove कर सकता है।
  • DELETE सभी rows हटाने पर भी table की structure बनी रहती है।
  • INSERT में specified columns और values का क्रम सही होना चाहिए।

Board Focus

Exam के लिए याद रखें:
DML → Data Manipulation Language
INSERT → New records जोड़ना
UPDATE → Existing records modify करना
DELETE → Records हटाना
WHERE → Specific records identify करना
INSERT INTO → Table में data insert करना
UPDATE ... SET → Data modify करना
DELETE FROM → Records delete करना

Board Important Questions

Very Short Answer Questions

Q1. DML का full form क्या है?

Answer: Data Manipulation Language.

Q2. DML का उपयोग किस लिए किया जाता है?

Answer: Table में stored data को manipulate करने के लिए।

Q3. नया record insert करने के लिए कौन-सा command उपयोग किया जाता है?

Answer: INSERT.

Q4. Existing record को modify करने के लिए कौन-सा command उपयोग किया जाता है?

Answer: UPDATE.

Q5. Record delete करने के लिए कौन-सा command उपयोग किया जाता है?

Answer: DELETE.

Q6. Specific records को identify करने के लिए कौन-सा clause उपयोग किया जाता है?

Answer: WHERE.

Q7. क्या DELETE FROM Student; table की structure को delete करता है?

Answer: नहीं। यह table की rows को delete करता है, table की structure बनी रहती है।

Q8. UPDATE command में SET keyword का क्या उपयोग है?

Answer: Column की नई value specify करने के लिए।

Q9. क्या INSERT command से एक से अधिक records insert किए जा सकते हैं?

Answer: हाँ।

Q10. DML का एक command लिखिए।

Answer: INSERT.

Short Answer Questions

Q11. INSERT command को उदाहरण सहित समझाइए।

Answer: INSERT command का उपयोग table में नए records जोड़ने के लिए किया जाता है।

INSERT INTO Student
VALUES (101, 'Rahul', 12, 85);
Output:
1 row inserted successfully.

Q12. UPDATE command क्या है?

Answer: UPDATE command का उपयोग existing records की values को modify करने के लिए किया जाता है।

UPDATE Student
SET Marks = 90
WHERE RollNo = 101;
Output:
1 row updated successfully.

Q13. DELETE command क्या है?

Answer: DELETE command का उपयोग table से records को remove करने के लिए किया जाता है।

DELETE FROM Student
WHERE RollNo = 101;
Output:
1 row deleted successfully.

Q14. UPDATE और DELETE में WHERE clause का क्या महत्व है?

Answer: WHERE clause specific records को identify करता है। इसके बिना UPDATE सभी rows की values बदल सकता है और DELETE सभी rows को remove कर सकता है।

Q15. DDL और DML में अंतर बताइए।

Answer: DDL database objects की structure को create और modify करने के लिए उपयोग होती है, जबकि DML tables में stored records को insert, update और delete करने के लिए उपयोग होती है।

Long Answer Questions

Q16. DML की प्रमुख commands को उदाहरण सहित समझाइए।

Answer: DML की प्रमुख commands INSERT, UPDATE और DELETE हैं। INSERT नए records को table में जोड़ता है। UPDATE existing records की values को modify करता है और DELETE records को remove करता है।

INSERT INTO Student
VALUES (104, 'Neha', 12, 95);

UPDATE Student
SET Marks = 98
WHERE RollNo = 104;

DELETE FROM Student
WHERE RollNo = 104;
Output:
1 row inserted.
1 row updated.
1 row deleted.

Q17. INSERT command के विभिन्न forms को समझाइए।

Answer: INSERT command का उपयोग complete record, selected columns या multiple records insert करने के लिए किया जा सकता है।

INSERT INTO Student
VALUES (101, 'Rahul', 12, 85);

INSERT INTO Student (RollNo, Name, Marks)
VALUES (102, 'Priya', 91);

INSERT INTO Student (RollNo, Name, Class, Marks)
VALUES
(103, 'Aman', 12, 78),
(104, 'Neha', 12, 95);

Q18. UPDATE command को उदाहरण सहित समझाइए।

Answer: UPDATE command existing records की values को बदलने के लिए उपयोग किया जाता है। SET clause नई values specify करता है और WHERE clause निर्धारित करता है कि कौन-से records update होंगे।

UPDATE Student
SET Marks = 95
WHERE RollNo = 102;
Output:
Marks of RollNo 102 updated to 95.

Q19. DELETE command को उदाहरण सहित समझाइए।

Answer: DELETE command table से records remove करने के लिए उपयोग किया जाता है। WHERE clause का उपयोग करके specific records delete किए जा सकते हैं।

DELETE FROM Student
WHERE Marks < 40;
Output:
Records with Marks less than 40 deleted.

Q20. DML commands और उनके उपयोगों को तालिका द्वारा समझाइए।

Command Use Important Keyword
INSERT New records add करना VALUES
UPDATE Existing records modify करना SET, WHERE
DELETE Records remove करना WHERE

Practice Questions

  1. DML क्या है?
  2. DML का full form लिखिए।
  3. DML की प्रमुख commands लिखिए।
  4. INSERT command का उपयोग समझाइए।
  5. INSERT INTO command का syntax लिखिए।
  6. Table में एक नया record insert करने का SQL command लिखिए।
  7. एक ही command से multiple records कैसे insert किए जाते हैं?
  8. UPDATE command क्या है?
  9. UPDATE command का syntax लिखिए।
  10. किसी specific student के marks update करने का SQL command लिखिए।
  11. DELETE command क्या है?
  12. DELETE command का syntax लिखिए।
  13. किसी specific record को delete करने का SQL command लिखिए।
  14. WHERE clause का क्या उपयोग है?
  15. WHERE clause के बिना UPDATE command चलाने पर क्या हो सकता है?
  16. WHERE clause के बिना DELETE command चलाने पर क्या हो सकता है?
  17. DDL और DML में अंतर लिखिए।
  18. INSERT, UPDATE और DELETE commands को उदाहरण सहित समझाइए।
  19. DML commands में WHERE clause का महत्व समझाइए।
  20. DELETE और TRUNCATE में अंतर लिखिए।

Quick Revision

  • DML: Data Manipulation Language
  • INSERT: New records add करता है।
  • UPDATE: Existing records modify करता है।
  • DELETE: Records remove करता है।
  • WHERE: Specific records को target करता है।
  • SET: UPDATE में नई values specify करता है।
  • VALUES: INSERT में values specify करता है।
  • DELETE बिना WHERE: सभी rows delete हो सकती हैं।
  • UPDATE बिना WHERE: सभी rows update हो सकती हैं।
  • DELETE: Table structure को नहीं हटाता।
One-Line Revision: SQL की Data Manipulation Language (DML) में मुख्यतः INSERT, UPDATE और DELETE commands शामिल हैं, जिनका उपयोग table में data को add, modify और remove करने के लिए किया जाता है।
Lesson 25 of 37
On This Page