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

Basic SQL

SQL is used to perform operations on data in a relational database. It includes commands to define schemas with DDL, manipulate data with DML, and query across multiple tables. DDL is used to create, alter, and drop database objects like tables. DML allows inserting, updating, deleting, and selecting data from tables.

Uploaded by

lossno26
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Basic SQL

SQL is used to perform operations on data in a relational database. It includes commands to define schemas with DDL, manipulate data with DML, and query across multiple tables. DDL is used to create, alter, and drop database objects like tables. DML allows inserting, updating, deleting, and selecting data from tables.

Uploaded by

lossno26
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

SQL

(Structured Query Language)


DBMS

1
SQL stands for Structured Query Language, SQL is standard language by which
the various operation can be performed on data stored in a relational database, the
operations like storing, manipulating and retrieving data.
With the help of SQL Commands the various tasks can be performed, like a create
a table, add data to tables, drop the table, modify the table, set permission for
users.
SQL commands are instructions, which is used to communicate with the database.
It is also used to perform specific tasks, functions and queries of data.
SQL uses compact english like statements and performs very complex jobs to
access information from very large sized databases.

2
Data Definition Language (DDL)

DDL is used to create, drop & alter the database or database


objects like table, views etc. It is used also to create other
object of database like views, indexes etc.
It contains commands like
• create
• drop
• alter.

3
 Create Database / Table
CREATE DATABASE adm_db
DROP DATABASE <database name>

The following statement in the SQL language defines the student table:
create table student(stu_id integer,
stu_name char(30),
age integer,
course char(5))
rename TABLE form_in to form_input

4
 Alter Table
The following statements in the SQL language defines the alter
student table:

alter table student MODIFY stu_id char(3)


alter table student MODIFY stu_id char(15)
alter table student MODIFY stu_id integer

alter table student drop stu_id


ALTER TABLE student add form_no int
ALTER TABLE student CHANGE stu_id form_no INT <(rename)>

5
 Drop Table
The following statement in the SQL language defines the drop
student table:

drop TABLE student

6
Data Manipulation Language (DML)
DML is used
• To retrieve data from the table,
• To insert data into a table
• To update data in the table
• To delete data from the table
It is the following commands:
• select
• insert
• update
• delete

7
SELECT
Select * from form_input
SELECT form_no,stu_name FROM form_input
Select * from stu where form_no=1234
SELECT * FROM form_input WHERE course_code=2

SELECT * FROM form_input WHERE course_code=4 and


session='2020-21'

8
INSERT
INSERT INTO form_input(form_no, stu_name, age, course, f_name)
VALUES (1234,'Amar Sahu',25,‘MCA',‘M. Sahu')

For some specific fields


INSERT INTO form_input(form_no, stu_name, course, ) VALUES
(1234, 'Salman Samar',‘MCA')

INSERT INTO `form_input`(`form_no`, `stu_name`, `age`, `course`,


`f_name`, `session`) VALUES(1237,'Amar Sahu',25,‘MCA','M.
Sahu','2019-20')

9
UPDATE
UPDATE `form_input`
SET `stu_name`= 'Amar Singh' WHERE `form_no`=1237

UPDATE `form_input`
SET `course_code`= 3 WHERE `course`=‘MCA’ and `session`=‘2020-21’

UPDATE `course`
SET `course_code`= 2 WHERE `course_name`=‘M.B.A‘

UPDATE `form_input` SET `course_code`=1


DELETE
DELETE FROM `form_input` WHERE stu_name='Amar'

10
Create table course & Insert data into course table
create table course(course_code integer,
course_name char(6),course_full_name char(30))
INSERT INTO `course`(`course_code`, `course_name`, `course_full_name`)
VALUES (1,'B.C.A.','Bachelor of Computer Application')
INSERT INTO `course`(`course_code`, `course_name`, `course_full_name`)
VALUES (2,'B.B.A.','Bachelor of Business Administration')
INSERT INTO `course`(`course_code`, `course_name`, `course_full_name`)
VALUES (4,'M.C.A.','Master of Computer Application')

11
Querying Multiple Tables – Retrieve data from two related tables
SELECT * FROM form_input, course WHERE course.course_code=form_input.course_code

12
Querying Multiple Tables – Retrieve some specific data(i.e. form_no, stu_name &
course_name) from two related tables
SELECT a.form_no,a.stu_name,b.course_name FROM form_input a, course b WHERE
a.course_code=b.course_code

13
References:
•North, Silbertz, Sudarshan, “Database Concepts”, Tata Mcgraw-hill Education
(India) Pvt. Ltd.
•Date C J, “An Introduction To Database System”, Addision Wesley
• Jain, Pillai, Singh “Introduction to Database Management”, BPB Publications.

14

You might also like