0% found this document useful (0 votes)
12 views4 pages

MySQL Class 11 Examples

This document provides MySQL command examples tailored for Class 11 students, covering essential database operations such as creating and deleting databases, creating and modifying tables, and performing CRUD operations. It includes specific commands for inserting, selecting, updating, and deleting records, as well as altering table structures. The examples aim to prepare students for frequently asked MySQL questions in exams.

Uploaded by

nairtanush3
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views4 pages

MySQL Class 11 Examples

This document provides MySQL command examples tailored for Class 11 students, covering essential database operations such as creating and deleting databases, creating and modifying tables, and performing CRUD operations. It includes specific commands for inserting, selecting, updating, and deleting records, as well as altering table structures. The examples aim to prepare students for frequently asked MySQL questions in exams.

Uploaded by

nairtanush3
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

MySQL Examples – Class 11

1. Database Related Examples


Create a database named school:
CREATE DATABASE school;

Select the database school:


USE school;

Show all databases:


SHOW DATABASES;

Delete a database:
DROP DATABASE school;

2. Table Creation Examples


Create a table STUDENT:
CREATE TABLE student ( roll_no INT, name VARCHAR(50), class INT, section CHAR(1) );

Create a table EMPLOYEE:


CREATE TABLE employee ( emp_id INT, emp_name VARCHAR(40), salary INT );
3. INSERT Command Examples
Insert a single record:
INSERT INTO student VALUES (1, 'Aarav', 11, 'A');

Insert multiple records:


INSERT INTO student VALUES (2,'Riya',11,'B'), (3,'Kabir',11,'A');

Insert selected columns:


INSERT INTO student (roll_no, name) VALUES (4, 'Ananya');

4. SELECT Command Examples


Display all records:
SELECT * FROM student;

Display specific columns:


SELECT name, class FROM student;

Use WHERE clause:


SELECT * FROM student WHERE class = 11;

Use DISTINCT:
SELECT DISTINCT section FROM student;
5. UPDATE Examples
Update one record:
UPDATE student SET section='C' WHERE roll_no=2;

Increase salary:
UPDATE employee SET salary=30000 WHERE emp_id=101;

6. DELETE Examples
Delete specific record:
DELETE FROM student WHERE roll_no=3;

Delete all records:


DELETE FROM student;
7. ALTER TABLE Examples
Add a new column:
ALTER TABLE student ADD marks INT;

Modify datatype:
ALTER TABLE student MODIFY name VARCHAR(60);

Drop a column:
ALTER TABLE student DROP marks;

Rename table:
ALTER TABLE student RENAME TO student_details;

8. DESCRIBE & SHOW Examples


Describe table structure:
DESCRIBE student;

Show tables:
SHOW TABLES;

These examples are designed for Class 11 students and cover the most frequently asked MySQL commands in
exams.

Common questions

Powered by AI

The SHOW DATABASES command lists all existing databases on the server, providing an overview of available data environments. Similarly, SHOW TABLES displays all tables within a selected database, offering insights into the data structure and available resources within that database. Both commands are vital for managing data visibility and navigating through multiple databases and tables .

The DESCRIBE command in MySQL is crucial for understanding the structure of a table. It lists all columns, their types, and attributes such as keys and defaults. For beginners, DESCRIBE is fundamental as it provides a clear view of how data is organized within a table, aiding in writing accurate queries and understanding database design .

To insert multiple records into a table, use an INSERT command with multiple value sets: INSERT INTO student VALUES (2,'Riya',11,'B'), (3,'Kabir',11,'A');. After insertion, to ensure only distinct sections are selected, use the DISTINCT clause: SELECT DISTINCT section FROM student;. This selects each unique section present in the 'student' table .

The UPDATE command changes existing data within a table. For example, to increase an employee's salary, use: UPDATE employee SET salary=30000 WHERE emp_id=101;. This changes the salary of the employee with 'emp_id' 101 to 30,000. The command allows targeted alterations based on specified conditions .

To add a new column to an existing table, use the ALTER TABLE command. For example, to add a column 'marks' to the 'student' table, use ALTER TABLE student ADD marks INT;. To verify the change, the DESCRIBE command can be used: DESCRIBE student;. This command displays the table structure, confirming the addition of the 'marks' column .

To create a table named EMPLOYEE with columns for employee ID, name, and salary, use the command: CREATE TABLE employee ( emp_id INT, emp_name VARCHAR(40), salary INT );. This defines a table with three columns, each specified with an appropriate data type to store employee details .

The WHERE clause is used in a SELECT statement to filter records based on specified conditions. For instance, SELECT * FROM student WHERE class = 11; retrieves all records where the class is 11. This process allows for targeted data retrieval, focusing on specific criteria within the dataset .

Using ALTER TABLE, various modifications can be conducted: adding a new column (ALTER TABLE student ADD marks INT;), modifying a column's datatype (ALTER TABLE student MODIFY name VARCHAR(60);), dropping a column (ALTER TABLE student DROP marks;), and renaming the table (ALTER TABLE student RENAME TO student_details;). Each modification adjusts the table to meet evolving data needs .

To create a database named 'school', the command is CREATE DATABASE school;. To select this database for use, the command is USE school;. This sequence creates a database and then selects it for further operations .

The DELETE command removes records from a table. To delete a specific record, use a condition: DELETE FROM student WHERE roll_no=3;. This deletes the record where 'roll_no' is 3. To delete all records, simply use DELETE FROM student;, which removes all entries without dropping the table itself .

You might also like