pranavsql
pranavsql
INDEX
SERIOL TOPIC PAGE DATE SIGN
NO NO
1 SQL introduction 3
2 RDBMS 4
3 PRIMARY KEY 4
4 ADVANTAGES OF SQL 6
5 SQL COMMANDS 6
6 SELECTION COMMANDS 11
7 EXERCISE - 1 16
8 EXERCISE - 2 24
3
A data can be defined as facts about something that can be used in calculating
, reasoning or planning.
INFORMATION
When the data is presented in an organised way that has some meaning for
the recipient is called information .
DATABASE
The organised collection of related data or related information which is related
to some specific domain is called database .
DBMS
DBMS stands for Database Management System . It can be defined as the
system to modify, handle and retrieve any type of data
▪ Uses of DBMS
1. It is used to access the data .
2. It is used to create the data .
3. It is used to update the data .
4. It is used to delete the data.
RDBMS
RDBMS is called Relational Data Base Management System and it is the basis for SQL
and for all the wanted database management systems like MySQL , MSSQL server ,
Oracle etc. The data in RDBMS is stored in data base objects which are called as tables
or Relation . It consists of numerous columns and rows . for example:
A B C D
4
TOUPLES
(rows in
RDBMS)
RELATION (table in
RDBMS)
NULL VALUE
The null value in a table is a value in a field that appears to be blank which
means a field with a null value is a field with no value.
A B C D
1 NULL 3 4
VALUE
PRIMARY KEY
Primary Key is the unique key which is applied to the columns in the table . The
column to which we are applying the primary key should have unique values
and no value in the column should be null . The primary key gives the
information about each and every row of the particular column , if the column
has any null value then the primary key will not be able to tell the information
about that particular row . All the values in the colum should be different
because if the values are identical then the primary key would not be able to
find the value of that row where that repeated value is present.
A B C D E F
1 201 null 111 11 45
3 222 123 23 11 45
5
Here in the above table column A can be considered as the primary key
because hare in this column all the values are unique.
When no column in the table has the unique value then we apply the
primary key to the group of two columns because there rows when
combine form the unique value so they can be considered as the primary
key.
A B C D
1 2 null 21
2001 2 12 null
1 301 13 22
SQL
SQL stands for Structured Query Language. It is used for storing ,
manipulating and retrieving the data stored in a relational database.
ADVANTAGES OF SQL
1. It allows the user to access the data in RDBMS .
2. It allows the user to describe the data.
3. It allows the user to define the data in the database and manipulate that
data.
4. It allows the user to create and drop database and tables.
5. It allows the user to create and view procedures and functions in the
database.
6. It allows the user to set condition on the tables and procedures .
6
7. It allow the user to add the new data and delete the previous data from the
database .
SQL COMMANDS
SQL commands are the instructions used to communicate with the
database to perform tasks , functions and queries with data. SQL commands
can be used to search the database and to do other functions like creating
tables , adding data to the table and dropping tables .
DROP column_name ;
The example program is given below:
4)DELETE COMMAND
Drop command removes the table structure and also its value. Delete
command only removes the rows of the table that satisfy the condition
provided by the “where” clause and return the number of records deleted.
Syntax of DROP command is given below:
DELETE FROM table_name
Where condition;
The example program is given below:
9
5)UPDATE COMMAND
Update command is used to modify the data values in a table . It is the DML
(data manipulation language)
The syntax of the update command is given below:
UPDATE table_name
Set column_name = new value
Where condition;
The example program is given below:
6) SELECT COMMAND
Select command is used for many different purposes. Some of the purposes of
the select command are given below:
a) For showing all the rows and columns
Syntax:
SELECT * FROM table_name ;
The example program is given below:
10
d) For retrieving the data from the particular column based on some
condition
Syntax:
SELECT column name FROM table_name
Where condition;
The example program is given below:
E) For retrieving two columns in the output using logical AND operator
Syntax:
SELECT column1 , column2 from table_name
Where condition 1 AND condition 2;
The example program is given below:
7) ORDER BY COMMAND
We use the command ORDER BY to sort the data in the table .
Syntax :
SELECT * from table_name
ORDER BY column_name;
The example program is given below:
14
8) LIKE OPERATOR
It is used to show the columns names which have the like alphabets.
Syntax:
SELECT column_name from table_name
Where column name like a%;
The example program is given below:
(c) Retrieve the list of names , city , and state of all the clients
(d) List the various products available from product master table
17
f)Find the names of the salesman who have a salary equal to Rs 3000.
18
EXERCISE – 2
3)Display all the records whos name have John (can be any
where)
23
4)Display all the records whose name starts with ‘A’ and ends
with ‘n’.
5) Display all the records where name has ‘no’ case sensitive .
24
6) Display all the records who got marks in nineties but not 100.
7)Display all the records who have alex or deo anywhere in the
name column .
25
8)Display all the records who have alex or john anywhere in the
colum .
9) Display all the records who have alex or John anywhere in the
column ,
26
10) Display all the records who have ro anywhere inside the
column and got the marks in nineties .