Day 56 – SQL Basics: Create, Insert, Update, Delete
Class 11 Computer Science – Chapter 6
What is SQL? (SQL क्या है?)
SQL (Structured Query Language) is a standard language used to interact with and manage relational databases. It allows users to perform tasks like creating tables, inserting data, updating records, and deleting data.
SQL (स्ट्रक्चर्ड क्वेरी लैंग्वेज) एक मानक भाषा है जिसका उपयोग रिलेशनल डेटाबेस के साथ बातचीत करने और प्रबंधन के लिए किया जाता है। यह उपयोगकर्ताओं को टेबल बनाने, डेटा डालने, रिकॉर्ड अपडेट करने, और डेटा हटाने जैसे कार्य करने की अनुमति देता है।
Basic SQL Commands (मूल SQL कमांड्स)
- CREATE: Used to create a new table in the database.
CREATE: डेटाबेस में एक नया टेबल बनाने के लिए उपयोग किया जाता है। - INSERT: Used to add new data into a table.
INSERT: टेबल में नया डेटा डालने के लिए उपयोग किया जाता है। - UPDATE: Used to modify existing data in a table.
UPDATE: टेबल में मौजूदा डेटा को संशोधित करने के लिए उपयोग किया जाता है। - DELETE: Used to remove data from a table.
DELETE: टेबल से डेटा हटाने के लिए उपयोग किया जाता है।
Syntax and Examples (सिंटैक्स और उदाहरण)
1. CREATE Command
Syntax:
CREATE TABLE table_name (
column1 datatype,
column2 datatype,
column3 datatype,
...
);
Example:
CREATE TABLE Students (
StudentID INT PRIMARY KEY,
Name VARCHAR(50),
Age INT,
Grade VARCHAR(10)
);
2. INSERT Command
Syntax:
INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1, value2, value3, ...);
Example:
INSERT INTO Students (StudentID, Name, Age, Grade) VALUES (1, 'Alice', 18, 'A');
3. UPDATE Command
Syntax:
UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition;
Example:
UPDATE Students SET Age = 19, Grade = 'A+' WHERE StudentID = 1;
4. DELETE Command
Syntax:
DELETE FROM table_name WHERE condition;
Example:
DELETE FROM Students WHERE StudentID = 1;
Advantages of SQL (SQL के लाभ)
- Allows easy manipulation of large datasets.
बड़े डेटा सेट को आसानी से प्रबंधित करने की अनुमति देता है। - Provides a standard interface for database operations.
डेटाबेस संचालन के लिए एक मानक इंटरफ़ेस प्रदान करता है। - Supports complex queries for data retrieval.
डेटा पुनः प्राप्ति के लिए जटिल क्वेरी का समर्थन करता है।
Practice Questions
Multiple Choice Questions (MCQs)
- What does SQL stand for?
(a) Standard Query Language | (b) Structured Query Language | (c) Simple Query Language | (d) None - Which command is used to create a table in SQL?
(a) INSERT | (b) CREATE | (c) UPDATE | (d) DELETE - Which command is used to delete data from a table?
(a) DROP | (b) DELETE | (c) REMOVE | (d) None - What is the purpose of the UPDATE command?
(a) Modify table structure | (b) Modify existing data | (c) Add new data | (d) None - Which clause is used to specify a condition in SQL commands?
(a) WHERE | (b) WHEN | (c) IF | (d) None - What is the output of this SQL command?
INSERT INTO Students (StudentID, Name, Age, Grade) VALUES (2, 'Bob', 20, 'B');(a) A new table is created | (b) A new row is added to the Students table | (c) An existing row is updated | (d) None - Which of the following is not a valid SQL command?
(a) CREATE | (b) INSERT | (c) MODIFY | (d) DELETE - Which data type is used to store text in SQL?
(a) INT | (b) VARCHAR | (c) FLOAT | (d) None - What is a primary key in SQL?
(a) A unique identifier for each row | (b) A column to link tables | (c) A foreign key | (d) None - What is the result of this command?
DELETE FROM Students WHERE StudentID = 3;(a) A new table is created | (b) A row is deleted from the Students table | (c) All rows are deleted | (d) None
Answers to MCQs:
1: (b), 2: (b), 3: (b), 4: (b), 5: (a), 6: (b), 7: (c), 8: (b), 9: (a), 10: (b)
Short Answer Questions
- What is SQL, and why is it used?
Answer: SQL (Structured Query Language) is used to interact with and manage relational databases. - Write the syntax for the CREATE command in SQL.
Answer:CREATE TABLE table_name ( column1 datatype, column2 datatype, ... ); - What is the purpose of the WHERE clause in SQL?
Answer: The WHERE clause specifies the condition for data retrieval or modification. - Write a SQL command to insert a row into a table.
Answer:INSERT INTO Students (StudentID, Name, Age, Grade) VALUES (1, 'Alice', 18, 'A');
- What is the difference between DELETE and DROP commands?
Answer: DELETE removes rows from a table, while DROP deletes the entire table.
Long Answer Questions
- Explain the CREATE, INSERT, UPDATE, and DELETE commands with examples.
- Discuss the importance of SQL in database management.
- Write a program to create a table, insert data, and update it using SQL commands.
Post a Comment