SQL
SQL
BY - AYUSH PODDAR
SQL &
DATABASE
CLASS – 12
COMPUTER
SCIENCE
Contents
1) Introduction
2) Data Types
3) DDL
4) DML
5) DQL
6) Constraints
CONTENTS
Introduction - DBMS :
• Database Management System
Data • Software used to manage databases.
Collection of raw, unorganized facts and details • Acts as an interface between the database &
like text, observations, figures, symbols etc. end users
Measured in terms of bits and bytes. • Lets us Add, Remove, Update, Delete Data.
• Reduces Duplicacy, Saves Time, Secured,
Accessibility etc.
Information
• For eg. - MySql, Oracle ........etc.
Processed, Organized & Structured form of data.
Use Cases -
Database :
Banking, Schools, Hospitals, Colleges etc.
Collection of Inter related data.
E.g. : (Teacher-Student), (Doctor-Patient) DBMS over File System -
INTRODUCTION
Char Varchar
Fixed Length Variable Length
Memory Wastage No Memory Wastage
SQL
Char(20) Varchar(20)
S_Name S_Age S_DOB
Chaman 69 2005/06/03
Kamla 55 2006/09/24
Pushpa 23 2009/05/14
© Youth Af
Q) Write a SQL code to insert values in YOUTHAF S_Name S_Age S_DOB
Chaman 69 2005/06/03
INSERT INTO YOUTHAF VALUES
( ‘ Chaman’ , 69 , ‘ 2005/06/03 ’ ) ; Kamla 55 2006/09/24
Pappu 2003/02/16
S_Name S_Age S_DOB
Chaman 69 2005/06/03
INSERT INTO YOUTHAF VALUES (S_Name, S_DOB)
( ‘ Pappu’ , ‘ 2003/02/16 ’ ) ;
INSERT INTO YOUTHAF VALUES
( ‘ Chaman’ , 69 , ‘ 2005/06/03 ’ ) , NOTE:
( ‘ Kamla’ , 55 , ‘ 2006/09/24 ’ ) ; Except numerical values everything is enclosed
in quotation marks
S_Name S_Age S_DOB
Chaman 69 2005/06/03
Kamla 55 2006/09/24
SQL
© Youth Af
Relation : Other name of table Q) Create a table “STUD” with CONSTRAINTS :-
Attribute : Columns or Fields
Column Datatype Size Constraints
Tuple : Rows or Records
SRollNo Int Primary Key
Degree : No. of rows
SAdmNo Int
Cardinality : No. of columns SName Varchar 30 NOT NULL
SMarks Int Greater than 40
KEYS -
DOB Date NOT NULL
Primary Key : Unique Identification (Non Empty) Gender Char 1
Candidate Key : Keys which can act as Primary Key City Varchar 20 Default : Delhi
Alternate Key : All Candidate Keys except Primary
CREATE TABLE STUD
(
SRollNo INTEGER PRIMARY KEY ,
SAdmNo INTEGER ,
SName VARCHAR (30) NOT NULL ,
SMarks INTEGER CHECK (Smarks>40) ,
DOB DATE NOT NULL ,
Gender CHAR (1) ,
City VARCHAR DEFAULT ‘Delhi’ ,
SQL
);
CREATE TABLE STUD Q) Write the SQL command to remove column “Age”.
(
SRollNo INTEGER PRIMARY KEY , ALTER TABLE STUD
SAdmNo INTEGER , (
SName VARCHAR (30) NOT NULL , DROP AGE ;
SMarks INTEGER CHECK (Smarks>40) , );
DOB DATE NOT NULL ,
ALTER TABLE STUD
Gender CHAR (1) ,
(
City VARCHAR ,
DROP COLUMN AGE ;
);
);
SRollNo SAdmNo SName Smarks DOB Gender City
SRollNo SAdmNo SName Smarks DOB Gender City
© Youth Af
THANK YOU
NOTES IN DESCRIPTION