SQL Project File

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 20

GMT PUBLIC SCHOOL

JALANDHAR BYPASS,LUDHIANA

Affiliated to C.B.S.E., New Delhi codeno. 163035

INFORMATICS PRACTICES
(SESSION:2024-25)

PRACTICAL FILE

Submitted from-> Bhavya Verma


+1 Non Medical
Submitted to-> Ms. Monika Mehra
Table of Contents

1. About MySQL

2. DDL commands

3. DML commands

4. DQL commands

5. Practicals
About My SQL
SQL (Structured Query Language) is a standard language for accessing and
Manipulating databases. SQL commands are used to create, transform and retrieve
information from Relational Database Management Systems (RDBMS) and also to
create an interface between the user and database. By using SQL commands, one
can create database and perform other functions like creating tables,
adding records, modifying data, etc.

# DDL commands
1. Creating Databases
Syntax-
CREATE DATABASE <database_name>
For example,

2. Opening Databases
Syntax-
USE <database_name>
For example,

3. Removing Databases
Syntax-
DROP DATABASE <database_name>

For example,
4. Creating a Table
Syntax-
CREATE TABLE <table_name>
(
<column_name1><data_type>[(size)],(constraints, if any)
<column_name2><data_type>[(size)],

);
For example,

5. Viewing a Table structure


Syntax-
DESCRIBE <table-name>;
For example,
6. ALTER TABLE command
A. Adding a column to an existing table
Syntax-
ALTER TABLE <table_name>ADD(<column_name><data type>size);

B. Adding a column with Default Value


Syntax-
ALTER TABLE <table_name>
ADD(column_name1<data_type>default data);
For example,

C. Modifying an existing column definition


Syntax-
ALTER TABLE<table_name>
MODIFY(column_name1<data type1>);
For example,

7. DROP TABLE command


Syntax-
DROP TABLE <table_name>;
#DML commands
1. Inserting data into a table
A. Inserting data(for all the columns) into a table
Syntax-
INSERT INTO table_name
VALUES (value1,value2,value3…);
For example,

B. Inserting data by specifying values into a table


Syntax-
INSERT INTO table_name (column1,column2,columnN,..)
VALUES (value1,value2,valueN,….);

C. Inserting NULL values into a table


For example-

2. Modifying data in a table


Syntax for UPDATE-
UPDATE <table_name>
SET<column1> = <value1>,<column2> = <value2>,….
WHERE <column_name> = <new_value>;
For example,
A. Updating values of multiple columns
For example,

B. Updating NULL values


For example,

C. Updating specific row using formula


For example,

D. Updating all rows using an expression


For example,

3. Removing specific data from a table


Syntax for DELETE statement-
DELETE FROM table_name WHERE <condition>;

A. Deleting all rows from a table


For example,

# DQL commands
->SQL SELECT statement
1. Projection
For example,

2. Selection
Syntax-
SELECT * FROM <table_name>
WHERE <conditions_to_satisfy>;

For example,
-> Using WHERE clause
For example,

3. Re-ordering Columns
For example,

4. Eliminating Duplicate Data


Syntax-
SELECT DISTINCT <column_name> from <table_name>;
For example,
->SQL Operators
A. Arithmetic Operators
For example,
B. Relational Operators
For example,
C. Logical Operators
1. AND operator
For example,

2. OR operator
For example,

3. NOT operator
For example,
D. SQL Special Operators
1. BETWEEN
Syntax-
SELECT <column_name> FROM <table_name>
WHERE <column_name> BETWEEN <value1> AND <value2>;
For example,

2. IN
Syntax-
SELECT <column_name> FROM <table_name>
WHERE <column_name> IN (value1,value2,…);

For example,
3. NULL
For example,

4. LIKE
Syntax-
SELECT <column_name> FROM <table_name>
WHERE <column_name> LIKE <pattern>;

For example,

->Sorting in SQL
Syntax-
SELECT <column_list> FROM <table_name>
WHERE <condition> ORDER BY <column_name>[ASC|DESC];

For example,
PRACTICALS
#1 Creating table SKILL_SUBJECTS_PREFERENCE

# Creating table STUDENT


# Creating table SHOP
# Creating table PRODUCTS
# Creating table BOOKS

You might also like