0% found this document useful (0 votes)
8 views

DATABASE DDL DML Commands

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

DATABASE DDL DML Commands

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

DATABASE

Database

A database is an organized collection of structured information, or data, typically stored


electronically in a computer system.
They are used in a variety of settings, including business, scientific, and government
organizations.

Important of Database

It helps you understand your customers, track your inventory, and make informed decisions.
But without proper database management, your data can quickly become disorganized and
unusable. Database management is the process of organizing and storing data in a way that
makes it easy to find, use, and analyze
DATABASE LANGUAGES

DATA DEFINITION LANGUAGE DATA MANIPULATION LANGUAGE

CREATE ALTER DROP TRUNCATE RENAME INSERT SELECT UPDATE DELETE


DDL Commands
• CREATE TABLE − Used to create a new table in the database.
• ALTER TABLE − Used to modify the structure of an existing table in the database.
• DROP TABLE − Used to delete a table and all its data from the database.
• TRUNCATE – used to empty a table of its contents, while keeping the table structure intact
• used to remove all of the rows from a table, regardless of whether or not any conditions are met and
resets the table definition
• RENAME - Any database user can easily change the name by using the RENAME TABLE and
ALTER TABLE statement in Structured Query Language
DML Commands
• INSERT − Used to add new data to a table.
• UPDATE − Used to modify existing data in a table.
• DELETE − Used to remove data from a table.
• SELECT − Used to retrieve data from one or more tables in a database.
DATA DEFINITION LANGUAGE

CREATE
SYNTAX FOR CREATING DATABASE USING SQL EXAMPLE FOR CREATING A DATABASE USING SQL

1.CREATE Database Database_Name; 1.CREATE Database Students;

OUTPUT FOR CREATING A DATABASE USING SQL

STUDENT DATABASE CREATED


SYNTAX FOR CREATING A TABLE USING SQL EXAMPLE FOR CREATING A TABLE USING SQL

1.CREATE TABLE table_name 1.CREATE TABLE Students


2.( 2.(
3.column_Name1 data_type ( size of the column ) , 3.Stud_id int,
4.column_Name2 data_type ( size of the column) , 4.First_name varchar(10),
5.column_Name3 data_type ( size of the column) , 5.Last_name varchar(10),
6.... 6.Age int,
7.column_NameN data_type ( size of the column ) 7.Marks int
8.) ; 8.);

OUTPUT FOR CREATING A TABLE USING SQL

Stud_id First_name Last_name Age Marks


DATA MANIPULATION LANGUAGE

INSERT
SYNTAX FOR INSERTING A EXAMPLE FOR INSERTING A
TABLE USING SQL TABLE USING SQL
1.INSERT INTO table_n 1.INSERT INTO Stude
ame nts
2.( 2.(
3.column_Name1 , 3.Stud_id,
4.column_Name2 , 4.First_name,
5.column_Name3 , 5.Last_name,
6..... 6.Age,
7.column_NameN 7.Marks Stud_id First_name Last_name Age Marks
8. ) 8.)
9.VALUES 9.VALUES 1 Anil Kumar 25 95
10.( 10.(
11.value_1, 11.01,
12.value_2, 12.'Anil’,
13.value_3, 13.'Kumar’,
14..... 14.25,
15.value_N 15.95
16.) ; 16.);
DATA MANIPULATION LANGUAGE

SELECT
Retrieving The Data Using Select
Command

Stud_id First_name Last_name Age Marks


1 Anil Kumar 25 95
2 Sathish Sagar 24 90
3 Venu Kumar 24 89
4 Vinod Sethi 24 98
5 Sidhi Sampath 28 97
SYNTAX FOR SELECTING A TABLE USING SQL EXAMPLE FOR SELECTING ATABLE USING SQL

1.SELECT * FROM table_name 1.SELECT * FROM Students

OUTPUT FOR SELECTING A TABLE USING SQL

Stud_id First_name Last_name Age Marks


1 Anil Kumar 25 95
2 Sathish Sagar 24 90
3 Venu Kumar 24 89
4 Vinod Sethi 24 98
5 Sidhi Sampath 28 97
SYNTAX FOR SELECTING A COLUMNS IN A TABLE EXAMPLE FOR SELECTING A COLUMNS IN A TABLE
USING SQL USING SQL

1.SELECT
2.column_Name_1, 1.SELECT
3.column_Name_2, 2.Stud_id,
4.….., 3.First_name,
5.column_Name_N 4.Marks
6.FROM 5.FROM
7.Name_of_table; 6.Students;

OUTPUT FOR SELECTING A COLUMNS IN A TABLE USING SQL

Stud_id First_name Last_name Marks


1 Anil Kumar 95
2 Sathish Sagar 90
3 Venu Kumar 89
4 Vinod Sethi 98
5 Sidhi Sampath 97
SYNTAX FOR SELECTING A ROW IN A TABLE USING SQL EXAMPLE FOR SELECTING A ROW IN TABLE USING SQL

1.SELECT * From Table_Name 1.SELECT * FROM Students


2.WHERE condition; 2. WHERE First _name = “Anil”;

OUTPUT FOR SELECTING A ROW IN TABLE USING SQL

Stud_id First_name Last_name Age Marks


1 Anil Kumar 25 95
DATA MANIPULATION LANGUAGE

Update
SYNTAX FOR UPDATING TABLE USING SQL EXAMPLE FOR UPDATING TABLE USING SQL

1. UPDATE table_name 1.UPDATE Students


2. SET 2.SET
3. column1 = value1, 3.First_name=“Nithin”
4. column2 = value2, ... 4.Age=“26”
5. WHERE condition; 5. WHERE Stud_id = 1;

OUTPUT FOR UPDATE TABLE USING SQL

Stud_id First_name Last_name Age Marks


1 Nithin Kumar 26 95
DATA DEFINITION LANGUAGE

ALTER

ADD ALTER
DROP RENAME
SYNTAX FOR ADDING INTO A TABLE USING SQL EXAMPLE FOR ADDING INTO A TABLE USING SQL

1. ALTER TABLE table_name ALTER TABLE Students


2. ADD column_name datatype; ADD ContactNo int;

OUTPUT FOR ADDING INTO A TABLE USING SQL

Contact
Stud_id First_name Last_name Age Marks
No
1 Nithin Kumar 26 95
SYNTAX FOR DROPING TABLE USING SQL EXAMPLE FOR DROPRING TABLE USING SQL

1. DROP TABLE Column_name; DROP Students ContactNo;

OUTPUT FOR DROPING TABLE USING SQL

Stud_id First_name Last_name Age Marks


1 Nithin Kumar 26 95
SYNTAX FOR RENAMING A COLUMN IN A TABLE USING SQL EXAMPLE FOR RENAMING A COLUMN IN A TABLE USING
SQL

1. ALTER TABLE table_name


ALTER TABLE Students
2. RENAME COLUMN old_column_name TO
RENAME COLUMN Marks TO Total_Marks;
new_column_name;

OUTPUT FOR RENAMING A COLUMN IN A TABLE USING SQL

Total_Mark
Stud_id First_name Last_name Age
s
1 Nithin Kumar 26 95
DATA DEFINITION LANGUAGE

DELETE
SYNTAX FOR DELETING A ROW IN A TABLE USING SQL EXAMPLE FOR DELETING A ROW IN A TABLE USING SQL

1. DELETE FROM table_name DELETE FROM Students


2. WHERE CONDITION; WHERE Stud_id=1;

OUTPUT FOR DELETING A ROW IN A TABLE USING SQL

Stud_id First_name Last_name Age Marks

2 Sathish Sagar 24 90
3 Venu Kumar 24 89
4 Vinod Sethi 24 98
5 Sidhi Sampath 28 97
Truncate:

Syntax:

TRUNCATE TABLE table_name;

Example:

TRUNCATE TABLE Student;

After running the above query Student table will be truncated, i.e, the data will be deleted but the structure
will remain in the memory for further operations.
Rename:

Syntax:

RENAME old_table _name To new_table_name

Example :

RENAME Employee To Coding_Employees

You might also like