SlideShare a Scribd company logo
Structured Query Language (SQL)
1.0 What is Data?
• In simple words, data can be facts related to
any object in consideration.
• For example, your name, age, height, weight,
etc. are some data related to you.
• A picture, image, file, pdf, etc. can also be
considered data.
1.0 What is Data? …
• We all are familiar with Social websites like Facebook & Instagram,
E-Commerce websites like Amazon & SnapDeal, Banking websites
like Barclays & HDFC or any Education website like ToolsQA, all
these websites have a humongous amount of data stored in it.
• So what is Data?
• Data is any sort of information which is stored in computer
memory.
• This information can later be used for a website, an application or any
other client to store for future purpose.
• The most common information is User information in the form of user
personal, address and banking information.
1.0 What is Data? …
• Let’s consider Facebook, it stores our personal data, images, posts, comments
and many more things.
• Banking application also stores user data, their transactions details, funds summary etc.
• All this information is data, but when it put together and store in a structural
way, it becomes informational data.
• But, how do these applications or websites get data?
• When you post a status on Facebook, perform a banking transaction online or upload a
selfie on Instagram, you are actually sending data to the site or to be precise their server.
• So, we can say any information transmitted or transferred is actually data.
• Server filter out the necessary data and stores it in Database (DB).
1.1 Data, Information, and Knowledge
• Data are the raw bits and pieces of information with no context.
• If I told you, “15, 23, 14, 85,” you would not have learned anything.
• But I would have given you data.
• Data can be quantitative or qualitative.
• Quantitative data is numeric, the result of a measurement, count, or some other
mathematical calculation.
• Qualitative data is descriptive. “Ruby Red,” the color of a 2013 Ford Focus, is an
example of qualitative data.
• A number can be qualitative too: if I tell you my favorite number is 5, that is
qualitative data because it is descriptive, not the result of a measurement or
mathematical calculation.
1.1 Data, Information, and Knowledge…
1.1 Data, Information, and Knowledge…
• By itself, data is not that useful.
• To be useful, it needs to be given context.
• Returning to the example above, if I told you that “15, 23, 14, and 85″ are the numbers of students that had
registered for upcoming classes, that would be information.
• By adding the context – that the numbers represent the count of students registering for specific classes – I have
converted data into information.
• Once we have put our data into context, aggregated and analyzed it, we can use it to make decisions for our
organization.
• We can say that this consumption of information produces knowledge.
• This knowledge can be used to make decisions, set policies, and even spark innovation.
• The final step up the information ladder is the step from knowledge (knowing a lot about a topic) to wisdom.
• We can say that someone has wisdom when they can combine their knowledge and experience to produce a deeper
understanding of a topic.
• It often takes many years to develop wisdom on a particular topic, and requires patience.
1.1 Examples of Data
• Almost all software programs require data to do anything useful.
• For example, if you are editing a document in a word processor such
as Microsoft Word, the document you are working on is the data.
• The word-processing software can manipulate the data: create a
new document, duplicate a document, or modify a document.
• Some other examples of data are: an MP3 music file, a video file, a
spreadsheet, a web page, and an e-book.
• In some cases, such as with an e-book, you may only have the ability
to read the data.
1.2 What is a Database (DB) ?
• The goal of many information systems is to transform data into information in order to generate
knowledge that can be used for decision making.
• In order to do this, the system must be able to take data, put the data into context, and provide tools for
aggregation and analysis.
• A database is designed for just such a purpose.
• A database is an organized collection of related information.
• It is an organized collection, because in a database, all data is described and associated with other data.
• All information in a database should be related as well; separate databases should be created to
manage unrelated information.
• For example, a database that contains information about students should not also hold information
about company stock prices.
• Databases are not always digital – a filing cabinet, for instance, might be considered a form of database.
• For the purposes of this text, we will only consider digital databases.
1.2 What is a Database (DB) ?…
• A database is a systematic collection of data.
• They support electronic storage and manipulation of data.
• Databases make data management easy.
• Let us discuss a few examples:
• An online telephone directory uses a database to store data of people, phone numbers, other contact
details.
• Your electricity service provider uses a database to manage billing, client-related issues, handle fault
data, etc.
• Let us also consider Facebook.
• It needs to store, manipulate, and present data related to members, their friends, member activities,
messages, advertisements, and a lot more.
• We can provide a countless number of examples for the usage of databases.
1.2 What is a Database (DB) ?…
• So what is a Database?
• Is it a random collection of stuff all squeezed in together?
• No, Database (DB) are organized, they have a structure, and all the data they store it fits
into that structure.
• More specifically, a database is an electronic system that allows data to be stored, easily
accessed, manipulated and updated.
• So, we just saw the definition of databases but where in real life can we see such things?
• Well, we all are well aware of things like a telephone directory.
• Well, phonebook/telephone directory actually contains the name of people arranged in
order of their last names.
• So, we are able to store data and search it efficiently using the last name of the person, like
it’s really easy if I ask you to search for Tyagi, Vishu.
1.2 What is a Database (DB) ?…
• But an issue arrives if I ask you to search for every contact with the first name Martin.
• The issue here is, names are stored according to last names so searching for the first name is a lot trickier.
• So, a database is made up of two components mainly, data and a meaningful method for accessing and manipulating data.
• Without these two, a database is just a random set of data.
• A more precise example of a database can be a dictionary, which stores a large quantity of data as Key-Value pairs.
• At the same time, it also has a meaningful method to access data using the Key.
• Databases are quite similar to spreadsheets as they are mostly made up of tables which contain rows and columns like a
spreadsheet.
• A database needs to be hosted or created on some special database platform, some of the famous Database platforms are:
• PostgreSQL
• MySQL
• Microsoft Access
• SQLite
• We know that when we use any software, like an app, data is either added to the database, updated according to the
action or pulled as per the action we perform.
• But, the computer must have something to perform such action too.
• A software which can perform the various operations on databases is known as Database Management System (DBMS).
1.2 What is a Database (DB) ?…
• As the name suggests, a database is a place where all the data gets stored in a
structured format.
• It helps the users to easily access, manage and update the required information.
• So, in layman terms you can understand, a database as a big container wherein all the
information about a website, or an application is stored in a structured format.
• For example, a company can have various details of employees, such as name,
empID, email, blood group, salary, and so on.
• All these details can be stored in a database with the name “Employee” in a structured
format such as tables, hierarchy, etc.
• In any organization, be it a startup or a hyper-growth company, many
databases can be present, but it is very important to manage those databases
in a proper manner.
• So, next in this article let us understand how to manage these databases.
2.0 Database Management Systems (DBMS)
• There is no doubt in the fact that humongous amounts of
data get generated on a daily basis from various
applications, business sites in different formats.
• But, how do you think, we can handle data present in
various formats and generate useful insights.
• Well, to do that, we need the database management
systems(DBMS).
2.1 What is DBMS ? …
• DBMS or Database Management
System is a software application used
to access, create, and manage
databases.
• With the help of DBMS, you can easily
create, retrieve and update data in
databases.
• A DBMS consists of a group of
commands to manipulate the database
and acts as an interface between the
end-users and the database.
2.1 What is DBMS? …
• Database Management Systems also aims to facilitate an overview of the databases, by
providing a variety of administrative operations such as tuning, performance
monitoring, and backup recovery.
• Database Management Systems allows users to do the following:
 Define Data – Allows the users to create, modify and delete the definitions which define
the organization of the database.
 Update Data – Provides access to the users to insert, modify and delete data from the
database.
 Retrieve Data – Allows the users to retrieve data from the database based on the
requirement.
 Administration of users – Registers the users and monitors their action, enforces data
security, maintains data integrity, monitors performance and deals with concurrency
control.
2.2 Example of a DBMS
• Let us see a simple example of a university database.
• This database is maintaining information concerning students, courses, and grades in a university
environment.
• The database is organized as five files:
 The STUDENT file stores data of each student
 The COURSE file stores contain data on each course.
 The SECTION stores the information about sections in a particular course.
 The GRADE file stores the grades which students receive in the various sections
 The TUTOR file contains information about each professor.
• To define a database system:
o We need to specify the structure of the records of each file by defining the different types of data
elements to be stored in each record.
o We can also use a coding scheme to represent the values of a data item.
o Basically, your Database will have 5 tables with a foreign key defined amongst the various tables.
2.3 History of DBMS
• Here, are the important landmarks from the history:
 1960 - Charles Bachman designed first DBMS system
 1970 - Codd introduced IBM'S Information Management System (IMS)
 1976- Peter Chen coined and defined the Entity-relationship model also know as the ER model
 1980 - Relational Model becomes a widely accepted database component
 1985- Object-oriented DBMS develops.
 1990s- Incorporation of object-orientation in relational DBMS.
 1991- Microsoft ships MS access, a personal DBMS and that displaces all other personal DBMS
products.
 1995: First Internet database applications
 1997: XML applied to database processing. Many vendors begin to integrate XML into DBMS
products.
2.4 Characteristics of DBMS
• The following are a few characteristics of DBMS:
 Provides security and removes redundancy
 Self-describing nature of a database system
 Insulation between programs and data abstraction
 Support of multiple views of the data
 Sharing of data and multiuser transaction processing
 DBMS allows entities and relations among them to form tables.
 It follows the ACID concept (Atomicity, Consistency, Isolation, and Durability).
 DBMS supports multi-user environment that allows users to access and
manipulate data in parallel.
2.4 DBMS vs. Flat File
DBMS Flat File Management
System
• Multi-user access • It does not support
multi-user access
• Design to fulfill the need
for small and large
businesses
• It is only limited to
smaller DBMS system.
• Remove redundancy and
Integrity
• Redundancy and
Integrity issues
2.5 Users in a DBMS environment
Component
Name
Task
Application
Programmers
• The Application programmers write
programs in various programming
languages to interact with databases.
Database
Administrators
• Database Admin is responsible for
managing the entire DBMS system.
• He/She is called Database admin or
DBA.
End-Users • The end users are the people who
2.6 Popular DBMS Software
• Here, is the list of some popular DBMS system:
 MySQL
 Microsoft Access
 Oracle
 PostgreSQL
 dBASE
 FoxPro
 SQLite
 IBM DB2
 LibreOffice Base
 MariaDB
 Microsoft SQL Server etc.
2.7 Application of DBMS
Sector Use of DBMS
Banking •For customer information, account activities, payments,
deposits, loans, etc.
Airlines •For reservations and schedule information.
Universitie
s
•For student information, course registrations, colleges
and grades.
Telecommu
nication
•It helps to keep call records, monthly bills, maintaining
balances, etc.
Finance •For storing information about stock, sales, and
purchases of financial instruments like stocks and
bonds.
2.8 Types of DBMS
• Four Types of DBMS systems are:
 Hierarchical database
 Network database
 Relational database
 Object-Oriented database
2.8 Types of DBMS
1) Hierarchical DBMS
• In a Hierarchical database, model data is organized in a tree-like structure.
• Data is Stored Hierarchically (top down or bottom up) format.
• Data is represented using a parent-child relationship.
• In Hierarchical DBMS parent may have many children, but children have only one
parent.
2) Network Model
• The network database model allows each child to have multiple parents.
• It helps you to address the need to model more complex relationships like as the
orders/parts many-to-many relationship.
• In this model, entities are organized in a graph which can be accessed through several
paths.
2.8 Types of DBMS
3) Relational model
• Relational DBMS is the most widely used DBMS model because it is one of the
easiest.
• This model is based on normalizing data in the rows and columns of the tables.
• Relational model stored in fixed structures and manipulated using SQL.
4) Object-Oriented Model
• In Object-oriented Model data stored in the form of objects.
• The structure which is called classes which display data within it.
• It defines a database as a collection of objects which stores both data members
values and operations.
2.9 Advantages of DBMS
 DBMS offers a variety of techniques to store & retrieve data
 DBMS serves as an efficient handler to balance the needs of multiple applications
using the same data
 Uniform administration procedures for data
 Application programmers never exposed to details of data representation and storage.
 A DBMS uses various powerful functions to store and retrieve data efficiently.
 Offers Data Integrity and Security
 The DBMS implies integrity constraints to get a high level of protection against
prohibited access to data.
 A DBMS schedules concurrent access to the data in such a manner that only one user
can access the same data at a time
 Reduced Application Development Time
2.10 Disadvantages of DBMS
 Cost of Hardware and Software of a DBMS is quite high which
increases the budget of your organization.
 Most database management systems are often complex systems, so
the training for users to use the DBMS is required.
 In some organizations, all data is integrated into a single database
which can be damaged because of electric failure or database is
corrupted on the storage media
 Use of the same program at a time by many users sometimes lead
to the loss of some data.
 DBMS can't perform sophisticated calculations
2.11 When not to use a DBMS system?
• Although, DBMS system is useful.
• It is still not suited for specific task mentioned below:
• Not recommended when you do not have the budget or
the expertise to operate a DBMS.
• In such cases, Excel/CSV/Flat Files could do just fine.
3.0 DDL, DML, DCL, and TCL Commands
• Structured Query Language(SQL) as we all know is the database language by
the use of which we can perform certain operations on the existing database
and also we can use this language to create a database.
• SQL uses certain commands like Create, Drop, Insert etc. to carry out the
required tasks.
• These SQL commands are mainly categorized into four categories as:
1) DDL – Data Definition Language
2) DML – Data Manipulation Language
3) DCL – Data Control Language
4) TCL – Transaction Control Language
3.0 DDL, DML, DCL, and TCL Commands …
3.1 DDL Commands
• DDL is short name of Data Definition Language, which deals with database
schemas and descriptions, of how the data should reside in the database.
 CREATE - to create a database and its objects like (table, index, views, store
procedure, function, and triggers)
 ALTER - alters the structure of the existing database
 DROP - delete objects from the database
 TRUNCATE - remove all records from a table, including all spaces allocated
for the records are removed
 COMMENT - add comments to the data dictionary
 RENAME - rename an object
3.1 DDL Commands : Creating a Database
• To create a database in RDBMS, create command is used.
• Following is the syntax,
• Example for creating Database
• The above command will create a database named Test, which will
be an empty schema without any table.
• To create tables in this newly created database, we can again use the
create command.
CREATE DATABASE <DB_NAME>;
CREATE DATABASE Test;
3.1 DDL Commands : Creating a Table
• Create command can also be used to create tables.
• Now when we create a table, we have to specify the details of the columns of the tables too.
• We can specify the names and datatypes of various columns in the create command itself.
• Following is the syntax,
• Create table command will tell the database system to create a new table with the given table name
and column information.
CREATE TABLE <TABLE_NAME>
(
column_name1 datatype1,
column_name2 datatype2,
column_name3 datatype3,
column_name4 datatype4
);
creating Table
• The above command will create a new table with name
Student in the current database with 3 columns, namely
student_id, name and age.
• Where the column student_id will only store integer, name
will hold upto 100 characters and age will again store only
integer value.
CREATE TABLE Student
(
student_id INT,
name VARCHAR(100),
age INT
);
Table …
• If you are currently not logged into your database in which you want to create
the table then you can also add the database name along with table name,
using a dot operator .
• For example, if we have a database with name Test and we want to create a
table Student in it, then we can do so using the following query:
CREATE TABLE Test.Student
(
student_id INT,
name VARCHAR(100),
age INT
);
3.1 DDL Commands : Most commonly used datatypes for
Table columns
Dataty
pe
Use
INT used for columns which will store integer values.
FLOAT used for columns which will store float values.
DOUBL
E
used for columns which will store float values.
VARCH
AR
used for columns which will be used to store
characters and integers, basically a string.
CHAR used for columns which will store char
3.2 DDL Commands : ALTER command
• alter command is used for altering the table structure, such
as,
to add a column to existing table
to rename any existing column
to change datatype of any column or to
modify its size.
to drop a column from the table.
3.2 DDL Commands : ALTER command : Add a new
Column
• Using ALTER command we can add a column to any existing table.
• Following is the syntax,
• Here is an Example for this,
• The above command will add a new column address to the table student, which will hold
data of type varchar which is nothing but string, of length 200.
ALTER TABLE table_name ADD
(
column_name datatype
);
ALTER TABLE student ADD
(
address VARCHAR(200)
);
3.2 DDL Commands : ALTER command : Add multiple
new Columns
• Using ALTER command we can even add multiple new columns to any existing table.
• Following is the syntax,
• Here is an Example for this,
• The above command will add three new columns to the student table.
ALTER TABLE table_name ADD
(
column_name1 datatype1,
column-name2 datatype2,
column-name3 datatype3
);
ALTER TABLE student ADD
(
father_name VARCHAR(60),
mother_name VARCHAR(60),
dob DATE
);
3.2 DDL Commands : ALTER command : Add Column with
default value
• ALTER command can add a new column to an existing table with a default value too.
• The default value is used when no value is inserted in the column.
• Following is the syntax,
• Here is an Example for this,
• The above command will add a new column with a preset default value to the table student.
ALTER TABLE table_name ADD
(
column-name1 datatype1 DEFAULT some_value
);
ALTER TABLE student ADD
(
dob DATE DEFAULT '01-Jan-99'
);
3.2 DDL Commands : ALTER command : Modify an
existing Column
• ALTER command can also be used to modify data type of any existing column.
• Following is the syntax,
• Here is an Example for this,
• Remember we added a new column address in the beginning?
• The above command will modify the address column of the student table, to now hold up to 300 characters.
ALTER TABLE table_name modify
(
column_name datatype
);
ALTER TABLE student MODIFY
(
address varchar(300)
);
3.2 DDL Commands : ALTER command : Rename a
Column
• Using ALTER command you can rename an existing column.
• Following is the syntax,
• Here is an example for this,
• The above command will rename address column to location.
ALTER TABLE table_name RENAME
old_column_name TO new_column_name;
ALTER TABLE student RENAME
address TO location;
3.2 DDL Commands : ALTER command : Drop a Column
• ALTER command can also be used to drop or remove columns.
• Following is the syntax,
• Here is an example for this,
• The above command will drop the address column from the table student.
ALTER TABLE table_name DROP
(
column_name
);
ALTER TABLE student DROP
(
address
);
Rename a Table
TRUNCATE command
• TRUNCATE command removes all the records from a table.
• But this command will not destroy the table's structure.
• When we use TRUNCATE command on a table its (auto-increment) primary key is also initialized.
• Following is its syntax,
• Here is an example explaining it,
• The above query will delete all the records from the table student.
• In DML commands, we will study about the DELETE command which is also more or less
same as the TRUNCATE command.
TRUNCATE TABLE table_name
TRUNCATE TABLE student;
3.3 DDL Commands : DROP command
• DROP command completely removes a table from the database.
• This command will also destroy the table structure and the data stored in it.
• Following is its syntax,
• Here is an example explaining it,
• The above query will delete the Student table completely.
• It can also be used on Databases, to delete the complete database.
• For example, to drop a database,
• The above query will drop the database with name Test from the system.
DROP TABLE table_name
DROP TABLE student;
DROP DATABASE Test;
3.3 DDL Commands : RENAME query
• RENAME command is used to set a new name for any
existing table.
• Following is the syntax,
• Here is an example explaining it.
• The above query will rename the table student to
students_info
RENAME TABLE old_table_name to new_table_name
RENAME TABLE student to students_info;
3.4 SQL: Comments
• Comments are used to explain sections of SQL statements, or
to prevent execution of SQL statements.
• These comments can appear on a single line or span across
multiple lines.
• There are two types that you can use to create a comment in
SQL.
1. Single Line Comment (- -)
2. Multiple Lines Comment (/* */)
3.4 SQL: Comments : Single Line Comment (- -)
Syntax Using -- symbol
• The syntax for creating a SQL comment using the -- symbol in SQL
Server is:
Example - Comment on a Single Line
-- comment goes here
SELECT employee_id, last_name -- Author: MMC MNTDY
FROM employees;
(/* */)
Syntax Using /* and */ symbols
• The syntax for creating a SQL comment using /* and */
symbols in SQL Server (Transact-SQL) is:
• In SQL Server, a comment that starts with /* symbol and
ends with */ and can be anywhere in your SQL statement.
• This method of commenting can span several lines within
your SQL.
/* comment goes here */
(/* */) …
Example - Comment on a Multiple Lines
• Let's look at a SQL comment example that shows a SQL comment on its own
line:
• Here is a SQL comment that appears in the middle of the line:
• Here is a SQL comment that appears at the end of the line:
SELECT employee_id, last_name
/* Author: MMC MNTDY*/
FROM employees;
SELECT /* Author: MMC MNTDY*/
employee_id, last_name
FROM employees;
SELECT employee_id, last_name
/* Author: MMC MNTDY
Purpose: To show a comment that spans multiple lines in your SQL statement.
*/
FROM employees;
4.0 DML Commands
• DML is short name of Data Manipulation Language which deals with data manipulation
and includes most common SQL statements such SELECT, INSERT, UPDATE, DELETE, etc.,
and it is used to store, modify, retrieve, delete and update data in a database.
 SELECT - retrieve data from a database
 INSERT - insert data into a table
 UPDATE - updates existing data within a table
 DELETE - Delete all records from a database table
 MERGE - UPSERT operation (insert or update)
 CALL - call a PL/SQL or Java subprogram
 EXPLAIN PLAN - interpretation of the data access path
 LOCK TABLE - concurrency Control
command
• Data Manipulation Language (DML) statements are used for
managing data in database.
• DML commands are not auto-committed.
• It means changes made by DML command are not
permanent to database, it can be rolled back.
• Talking about the Insert command, whenever we post a
Tweet on Twitter, the text is stored in some table, and as we
post a new tweet, a new record gets inserted in that table.
command…
• Insert command is used to insert data into a table.
• Following is its general syntax,
• Lets see an example,
• Consider a table student with the following fields.
• The above command will insert a new record into student table.
INSERT INTO table_name VALUES(data1, data2, ...)
s_id name age
INSERT INTO student VALUES(101, 'Adam', 15);
s_id name age
101 Adam 15
4.1 DML Commands : Insert value into only specific
columns
• We can use the INSERT command to insert values for only
some specific columns of a row.
• We can specify the column names along with the values to
be inserted like this,
• The above SQL query will only insert id and name values in
the newly inserted record.
INSERT INTO student(id, name) values(102, 'Alex');
4.1 DML Commands : Insert NULL value to a
column
• Both the statements below will insert NULL value into age
column of the student table.
Or,
• The above command will insert only two column values and
the other column is set to null.
INSERT INTO student(id, name) values(102, 'Alex');
INSERT INTO Student VALUES(102,'Alex', null);
S_id S_Name age
101 Adam 15
102 Alex
4.1 DML Commands : Insert Default value to a
column
• Suppose the column age in our tabel has a default value of 14.
• Also, if you run the below query, it will insert default value into the age column, whatever
the default value may be.
INSERT INTO Student VALUES(103,'Chris', default)
INSERT INTO Student VALUES(103,'Chris')
S_id S_Name age
101 Adam 15
102 Alex
103 chris 14
4.2 DML Commands : SELECT SQL Query
• SELECT query is used to retrieve data from a table.
• It is the most used SQL query.
• We can retrieve complete table data, or partial by specifying conditions using
the WHERE clause.
Syntax of SELECT query
• SELECT query is used to retieve records from a table.
• We can specify the names of the columns which we want in the resultset.
SELECT
column_name1,
column_name2,
column_name3,
...
column_nameN
FROM table_name;
4.2 DML Commands : SELECT SQL Query
Time for an Example : Consider the following student table,
• The above query will fetch information of s_id, name and age columns of the student table
and display them,
• As you can see the data from address column is absent, because we did not specif it in our SELECT query.
SELECT s_id, name, age FROM student;
s_id name age address
101 Adam 15 Chennai
102 Alex 18 Delhi
103 Abhi 17 Banglore
104 Ankit 22 Mumbai
s_id Name age
101 Adam 15
102 Alex 18
103 Abhi 17
104 Ankit 22
4.2 DML Commands : SELECT SQL Query - Select all records from a
table
• A special character asterisk * is used to address all the data(belonging to all
columns) in a query.
• SELECT statement uses * character to retrieve all records from a table, for all
the columns.
• The above query will show all the records of student table, that means it will
show complete dataset of the table.
SELECT * FROM student;
s_id name age address
101 Adam 15 Chennai
102 Alex 18 Delhi
103 Abhi 17 Banglore
104 Ankit 22 Mumbai
4.2 DML Commands : SELECT SQL Query - Select a particular record based on a
condition
• We can use the WHERE clause to set a condition,
• The above query will return the following result,
SELECT * FROM student WHERE name = 'Abhi';
103 Abhi 17 Banglore
4.2 DML Commands : SELECT SQL Query - Performing Simple Calculations
using SELECT Query
• Consider the following employee table.
• Here is our SELECT query,
• The above command will display a new column in the result, with 3000 added into existing salaries of the employees.
• So you can also perform simple mathematical operations on the data too using the SELECT query to fetch data from table.
SELECT eid, name, salary+3000 FROM employee;
eid name age salary
101 Adam 26 5000
102 Ricky 42 8000
103 Abhi 25 10000
104 Rohan 22 5000
eid name salary+3000
101 Adam 8000
102 Ricky 11000
103 Abhi 13000
104 Rohan 8000
4.3 DML Commands : Using UPDATE SQL command
• Let's take an example of a real-world problem.
• These days, Facebook provides an option for Editing your status
update, how do you think it works?
• Yes, using the Update SQL command.
• Let's learn about the syntax and usage of the UPDATE command.
• UPDATE command is used to update any record of data in a table.
• Following is its general syntax,
• WHERE is used to add a condition to any SQL query.
UPDATE table_name SET column_name = new_value WHERE some_condition;
4.3 DML Commands : Using UPDATE SQL command
…
• Lets take a sample table student,
• In the above statement, if we do not use the WHERE clause, then our update
query will update age for all the columns of the table to 18.
UPDATE student SET age=18 WHERE student_id=102;
student_id name age
101 Adam 15
102 Alex
103 chris 14
S_id S_Name age
101 Adam 15
102 Alex 18
103 chris 14
4.3 DML Commands : Using UPDATE SQL command
…
Updating Multiple Columns
• We can also update values of multiple columns using a
single UPDATE statement.
• The above command will update two columns of the record
which has s_id 103.
UPDATE student SET name='Abhi', age=17 where s_id=103;
s_id name age
101 Adam 15
102 Alex 18
103 Abhi 17
4.3 DML Commands : Using UPDATE SQL command
…
Incrementing Integer Value
• When we have to update any integer value in a table, then we can
fetch and update the value in the table in a single statement.
• For example, if we have to update the age column of student table
every year for every student, then we can simply run the following
UPDATE statement to perform the following operation:
• As you can see, we have used age = age + 1 to increment the value of
age by 1.
• NOTE: This style only works for integer values.
UPDATE student SET age = age+1;
4.4 DML Commands : Using DELETE SQL command
• When you ask any question in Study tonight's Forum it gets saved into a
table.
• And using the Delete option, you can even delete a question asked by
you.
• How do you think that works?
• Yes, using the Delete DML command.
• Let's study about the syntax and the usage of the Delete command.
• DELETE command is used to delete data from a table.
• Following is its general syntax,
DELETE FROM table_name;
4.4 DML Commands : Using DELETE SQL command
…
• Let's take a sample table student:
Delete all Records from a Table
• The above command will delete all the records from the
table student.
DELETE FROM student;
s_id name age
101 Adam 15
102 Alex 18
103 Abhi 17
4.4 DML Commands : Using DELETE SQL command
…
Delete a particular Record from a Table
• In our student table if we want to delete a single record, we
can use the WHERE clause to provide a condition in our
DELETE statement.
• The above command will delete the record where s_id is 103
from the table student.
DELETE FROM student WHERE s_id=103;
4.4 DML Commands : Using DELETE SQL command
…
Isn't DELETE same as TRUNCATE
• TRUNCATE command is different from DELETE command.
• The delete command will delete all the rows from a table whereas truncate
command not only deletes all the records stored in the table, but it also re-
initializes the table(like a newly created table).
• For eg: If you have a table with 10 rows and an auto_increment primary key,
and if you use DELETE command to delete all the rows, it will delete all the
rows, but will not re-initialize the primary key, hence if you will insert any
row after using the DELETE command, the auto_increment primary key will
start from 11.
• But in case of TRUNCATE command, primary key is re-initialized, and it will
again start from 1.
5.0 TCL Commands
• Transaction Control Language(TCL) commands are used to manage
transactions in the database.
• These are used to manage the changes made to the data in a table
by DML statements.
• It also allows statements to be grouped together into logical
transactions
• These are-
 Commit,
 Rollback and
 Savepoint
5.1 TCL Commands : COMMIT command
• COMMIT command is used to permanently save any transaction
into the database.
• When we use any DML command like INSERT, UPDATE or DELETE, the
changes made by these commands are not permanent, until the current
session is closed, the changes made by these commands can be rolled back.
• To avoid that, we use the COMMIT command to mark the changes
as permanent.
• Following is commit command's syntax,
COMMIT;
5.2 TCL Commands : SAVEPOINT command…
• SAVEPOINT command is used to temporarily save a transaction so
that you can rollback to that point whenever required.
• Following is savepoint command's syntax,
• In short, using this command we can name the different states of
our data in any table and then rollback to that state using the
ROLLBACK command whenever required.
SAVEPOINT savepoint_name;
5.3 TCL Commands : ROLLBACK command
• This command restores the database to last commited state.
• It is also used with SAVEPOINT command to jump to a savepoint in an ongoing
transaction.
• If we have used the UPDATE command to make some changes into the
database, and realise that those changes were not required, then we can use
the ROLLBACK command to rollback those changes, if they were not
commited using the COMMIT command.
• Following is rollback command's syntax,
ROLLBACK TO savepoint_name;
5.4 TCL Commands : Examples
Using Savepoint and Rollback
• Following is the table class,
• Lets use some SQL queries on the above table and see the results.
id name
1 Abhi
2 Arunima
4 Alex
INSERT INTO class VALUES(5, 'Rahul');
COMMIT;
UPDATE class SET name = 'Abhijit' WHERE id = '5';
SAVEPOINT A;
INSERT INTO class VALUES(6, ‘Ameya');
SAVEPOINT B;
INSERT INTO class VALUES(7, 'Bravo');
SAVEPOINT C;
SELECT * FROM class;
5.4 TCL Commands : Examples …
• NOTE: SELECT statement is used to show the data stored in the table.
• The resultant table will look like,
id name
1 Abhi
2 Arunima
4 Alex
5 Abhijit
6 Ameya
7 Bravo
5.4 TCL Commands : Examples …
• Now let's use the ROLLBACK command to roll back the state of data to the
savepoint B.
• Now our class table will look like,
ROLLBACK TO B;
SELECT * FROM class;
id name
1 Abhi
2 Arunima
4 Alex
5 Abhijit
6 Ameya
5.4 TCL Commands : Examples …
• Now let's again use the ROLLBACK command to roll back the state of data to
the savepoint A
• Now the table will look like,
ROLLBACK TO A;
SELECT * FROM class;
id name
1 Abhi
2 Arunima
4 Alex
5 Abhijit
4.3 Using the WHERE SQL clause
• WHERE clause is used to specify/apply any condition while retrieving, updating or
deleting data from a table.
• This clause is used mostly with SELECT, UPDATE and DELETE query.
• When we specify a condition using the WHERE clause then the query executes only
for those records for which the condition specified by the WHERE clause is true.
Syntax for WHERE clause
• Here is how you can use the WHERE clause with a DELETE statement, or any other
statement,
• The WHERE clause is used at the end of any SQL query, to specify a condition for
execution.
DELETE FROM table_name WHERE [condition];
4.3 Using the WHERE SQL clause …
• Time for an Example : Consider a table student,
• Now we will use the SELECT statement to display data of the table, based on a condition,
which we will add to our SELECT query using WHERE clause.
• Let's write a simple SQL query to display the record for student with s_id as 101.
• Following will be the result of the above query.
SELECT s_id, name, age, address
FROM student WHERE s_id = 101;
s_id name age address
101 Adam 15 Chennai
102 Alex 18 Delhi
103 Abhi 17 Banglore
104 Ankit 22 Mumbai
s_id name age address
101 Adam 15 Noida
4.3 Using the WHERE SQL clause …
Applying condition on Text Fields
• In the above example we have applied a condition to an integer value field,
but what if we want to apply the condition on name field.
• In that case we must enclose the value in single quote ' ‘.
• Some databases even accept double quotes, but single quotes is accepted by
all.
• Following will be the result of the above query.
SELECT s_id,
name,
age,
address
FROM student WHERE name = 'Adam';
s_id name age address
101 Adam 15 Noida
4.3 Using the WHERE SQL clause: Operators for WHERE
clause condition
Operator Description
= Equal to
!= Not Equal to
< Less than
> Greater than
<= Less than or Equal to
>= Greate than or Equal to
BETWEEN Between a specified range of values
LIKE This is used to search for a pattern in value.
IN In a given set of values
5.0 SQL LIKE clause
• LIKE clause is used in the condition in SQL query with the
WHERE clause.
• LIKE clause compares data with an expression using wildcard
operators to match pattern given in the condition.
Wildcard operators
• There are two wildcard operators that are used in LIKE clause.
• Percent sign %: represents zero, one or more than one character.
• Underscore sign _: represents only a single character.
5.0 SQL LIKE clause: Example
• Consider the following Student table.
• The above query will return all records where s_name starts with character 'A’.
SELECT * FROM Student WHERE s_name LIKE 'A%';
s_id s_Name age
101 Arunima 15
102 Alex 18
103 Abhi 17
s_id s_Name age
101 Arunima 15
102 Alex 18
103 Abhi 17
8.0 SQL Aggregate Functions
• SQL aggregation function is used to
perform the calculations on multiple
rows of a single column of a table.
• It returns a single value.
• It is also used to summarize the data.
8.0 Why use Aggregate Functions ?
• From a business perspective, different organization levels have different
information requirements.
• Top levels managers are usually interested in knowing whole figures and not
necessary the individual details.
• Aggregate functions allow us to easily produce summarized data from our
database.
• For instance, from our myflix database , management may require following reports
• Least rented movies.
• Most rented movies.
• Average number that each movie is rented out in a month.
• We easily produce above reports using aggregate functions.
8.0 Types of SQL Aggregate Functions …
FUNCTION
• Count returns the number of rows present in the table
either based on some condition or without condition.
• Its general syntax is,
SELECT COUNT(column_name) FROM table-name
FUNCTION …
• Consider the following Emp table
• SQL query to count employees, satisfying specified condition is,
• Result of the above query will be,
SELECT COUNT(name) FROM Emp WHERE salary = 8000;
eid name age salary
401 Anu 22 9000
402 Shane 29 8000
403 Rohan 34 6000
404 Scott 44 10000
405 Tiger 35 8000
count(name)
2
FUNCTION …
• COUNT(DISTINCT expression) evaluates expression for each row in a group, and returns the number of
unique, non-null values.
• Example of COUNT(distinct) : Consider the following Emp table.
• SQL query is,
• Result of the above query will be,
SELECT COUNT(DISTINCT salary) FROM emp;
eid name age salary
401 Anu 22 9000
402 Shane 29 8000
403 Rohan 34 6000
404 Scott 44 10000
405 Tiger 35 8000
count(distinct salary)
4
FUNCTION
• SUM function returns total sum of a selected columns
numeric values.
• Syntax for SUM is,
SELECT SUM(column_name) from table-name;
FUNCTION …
• Consider the following Emp table
• SQL query to find sum of salaries will be,
• Result of the above query will be,
SELECT SUM(salary) FROM emp;
eid name age salary
401 Anu 22 9000
402 Shane 29 8000
403 Rohan 34 6000
404 Scott 44 10000
405 Tiger 35 8000
SUM(salary)
41000
FUNCTION
• Average returns average value after calculating it from
values in a numeric column.
• Its general syntax is,
SELECT AVG(column_name) FROM table_name
FUNCTION …
• Consider the following Emp table
• SQL query to find average salary will be,
• Result of the above query will be,
SELECT avg(salary) from Emp;
avg(salary)
8200
eid name age salary
401 Anu 22 9000
402 Shane 29 8000
403 Rohan 34 6000
404 Scott 44 10000
405 Tiger 35 8000
FUNCTION
• MAX function returns maximum value from selected
column of the table.
• Syntax of MAX function is,
SELECT MAX(column_name) from table-name;
FUNCTION …
• Using MAX() function :Consider the following Emp table
• SQL query to find the Maximum salary will be,
• Result of the above query will be,
SELECT MAX(salary) FROM emp;
eid name age salary
401 Anu 22 9000
402 Shane 29 8000
403 Rohan 34 6000
404 Scott 44 10000
405 Tiger 35 8000
MAX(salary)
10000
FUNCTION
• MIN function returns minimum value from a selected
column of the table.
• Syntax for MIN function is,
SELECT MIN(column_name) from table-name;
FUNCTION …
• Using MIN() function :Consider the following Emp table
• SQL query to find the Minimum salary will be,
• Result of the above query will be,
SELECT MIN(salary) FROM emp;
eid name age salary
401 Anu 22 9000
402 Shane 29 8000
403 Rohan 34 6000
404 Scott 44 10000
405 Tiger 35 8000
MIN(salary)
6000
FUNCTION
• First function returns first value of a selected column
• Syntax for FIRST function is,
SELECT FIRST(column_name) from table-name;
FUNCTION …
• Using FIRST() function :Consider the following Emp table
• SQL query will be,
• Result of the above query will be,
SELECT FIRST(salary) FROM Emp;
eid name age salary
401 Anu 22 9000
402 Shane 29 8000
403 Rohan 34 6000
404 Scott 44 10000
405 Tiger 35 8000
first(salary)
9000
FUNCTION
• LAST function returns the return last value of the selected
column.
• Syntax of LAST function is,
SELECT LAST(column_name) from table-name;
FUNCTION …
• Using LAST() function :Consider the following Emp table
• SQL query will be,
• Result of the above query will be,
SELECT LAST(salary) FROM Emp;
eid name age salary
401 Anu 22 9000
402 Shane 29 8000
403 Rohan 34 6000
404 Scott 44 10000
405 Tiger 35 8000
last(salary)
8000
FUNCTION
• Scalar functions return a single value from an input value.
• Following are some frequently used Scalar Functions in SQL.
• UCASE function is used to convert value of string column to
Uppercase characters.
• Syntax of UCASE,
SELECT UCASE(column_name) from table-name;
FUNCTION …
• Using UCASE() function :Consider the following Emp table
• SQL query for using UCASE is,
• Result is,
SELECT UCASE(name) FROM emp;
eid name age salary
401 Anu 22 9000
402 Shane 29 8000
403 Rohan 34 6000
404 Scott 44 10000
405 Tiger 35 8000
UCASE(name)
ANU
SHANE
ROHAN
SCOTT
TIGER
FUNCTION
• LCASE function is used to convert value of string columns to
Lowecase characters.
• Syntax for LCASE is,
SELECT LCASE(column_name) from table-name;
FUNCTION …
• Using LCASE() function :Consider the following Emp table
• SQL query for using LCASE is,
• Result is,
SELECT LCASE(name) FROM emp;
eid name age salary
401 Anu 22 9000
402 Shane 29 8000
403 Rohan 34 6000
404 Scott 44 10000
405 Tiger 35 8000
LCASE(name)
anu
shane
rohan
scott
tiger
FUNCTION
• MID function is used to extract substrings from column
values of string type in a table.
• Syntax for MID function is,
SELECT MID(column_name, start, length) from table-name;
FUNCTION …
• Using MID() function :Consider the following Emp table
• SQL query will be,
• Result is,
SELECT MID(name,2,2) FROM emp;
eid name age salary
401 Anu 22 9000
402 Shane 29 8000
403 Rohan 34 6000
404 Scott 44 10000
405 Tiger 35 8000
MID(name,2,2)
nu
ha
oh
co
ig
FUNCTION
• ROUND function is used to round a numeric field to number
of nearest integer.
• It is used on Decimal point values.
• Syntax of Round function is,
SELECT ROUND(column_name, decimals) from table-name;
FUNCTION …
• Using ROUND() function :Consider the following Emp table
• SQL query will be,
• Result is,
SELECT ROUND(salary) from emp;
eid name age salary
401 Anu 22 9000
402 Shane 29 8000
403 Rohan 34 6000
404 Scott 44 10000
405 Tiger 35 8000
ROUND(salary)
9001
8001
6000
10000
8000
9.0 SQL ORDER BY Clause
• Order by clause is used with SELECT statement for
arranging retrieved data in sorted order.
• The Order by clause by default sorts the retrieved data in
ascending order.
• To sort the data in descending order DESC keyword is used
with Order by clause.
• Syntax of Order By
SELECT column-list|* FROM table-name ORDER BY ASC | DESC;
9.1 SQL ORDER BY Clause …
• Using default Order by : Consider the following Emp table,
• The above query will return the resultant data in ascending order of the salary.
SELECT * FROM Emp ORDER BY salary;
eid name age salary
401 Anu 22 9000
402 Shane 29 8000
403 Rohan 34 6000
404 Scott 44 10000
405 Tiger 35 8000
eid name age salary
403 Rohan 34 6000
402 Shane 29 8000
405 Tiger 35 8000
401 Anu 22 9000
404 Scott 44 10000
9.2 SQL ORDER BY Clause …
• Using Order by DESC: Consider the following Emp table,
• The above query will return the resultant data in descending order of the salary.
SELECT * FROM Emp ORDER BY salary DESC;
eid name age salary
401 Anu 22 9000
402 Shane 29 8000
403 Rohan 34 6000
404 Scott 44 10000
405 Tiger 35 8000
eid name age salary
404 Scott 44 10000
401 Anu 22 9000
405 Tiger 35 8000
402 Shane 29 8000
403 Rohan 34 6000
10.0 SQL GROUP BY Clause
• Group by clause is used to group the results of a SELECT
query based on one or more columns.
• It is also used with SQL functions to group the result from
one or more tables.
• Syntax for using Group by in a statement.
SELECT column_name, function(column_name)
FROM table_name
WHERE condition
GROUP BY column_name
10.0 SQL GROUP BY Clause …
• Example of Group by in a Statement: Consider the following Emp table,
• Here we want to find name and age of employees grouped by their salaries or in
other words, we will be grouping employees based on their salaries, hence, as a
result, we will get a data set, with unique salaries listed, along side the first
employee's name and age to have that salary.
• group by is used to group different row of data together based on any one column.
eid name age salary
401 Anu 22 9000
402 Shane 29 8000
403 Rohan 34 6000
404 Scott 44 10000
405 Tiger 35 8000
10.0 SQL GROUP BY Clause …
• SQL query for the above requirement will be,
• Result will be,
SELECT name, age
FROM Emp GROUP BY salary
name age
Rohan 34
Shane 29
Anu 22
10.0 SQL GROUP BY Clause …
• Example of Group by in a Statement with WHERE clause: Consider the following Emp table,
• SQL query will be, group by is used to group different row of data together based on any one column.
• Result will be,
eid name age salary
401 Anu 22 9000
402 Shane 29 8000
403 Rohan 34 6000
404 Scott 44 10000
405 Tiger 35 8000
SELECT name, salary
FROM Emp
WHERE age > 25
GROUP BY salary
name salary
Rohan 6000
Shane 8000
Scott 9000
3.3 DCL Commands
• DCL is short name of Data Control Language which
includes commands such as GRANT and mostly
concerned with rights, permissions and other controls
of the database system.
 GRANT - allow users access privileges to the database
 REVOKE - withdraw users access privileges given by
using the GRANT command
3.4 TCL Commands
• TCL is short name of Transaction Control Language which deals
with a transaction within a database.
 COMMIT - commits a Transaction
 ROLLBACK - rollback a transaction in case of any error occurs
 SAVEPOINT - to rollback the transaction making points within
groups
 SET TRANSACTION - specify characteristics of the transaction

More Related Content

Similar to Structured Query Language (SQL)- standard Database language (20)

rdbms1-191014080818000000000000000000000000000000000
rdbms1-191014080818000000000000000000000000000000000rdbms1-191014080818000000000000000000000000000000000
rdbms1-191014080818000000000000000000000000000000000
VaibhavSrivastav52
 
MS-CIT Unit 9.pptx
MS-CIT Unit 9.pptxMS-CIT Unit 9.pptx
MS-CIT Unit 9.pptx
SHRIBALAJIINFOTECH
 
Introduction to Databases by Dr. Kamal Gulati
Introduction to Databases by Dr. Kamal GulatiIntroduction to Databases by Dr. Kamal Gulati
Introduction to Databases by Dr. Kamal Gulati
Amity University | FMS - DU | IMT | Stratford University | KKMI International Institute | AIMA | DTU
 
fundamentals of Databases
fundamentals of Databasesfundamentals of Databases
fundamentals of Databases
Berhanu Abebe Dagnaw
 
Components and Advantages of DBMS
Components and Advantages of DBMSComponents and Advantages of DBMS
Components and Advantages of DBMS
Shubham Joon
 
Module 1 - Chapter1.pptx
Module 1 - Chapter1.pptxModule 1 - Chapter1.pptx
Module 1 - Chapter1.pptx
SoniaDevi15
 
Lecture 1 =Unit 1 Part 1.ppt
Lecture 1 =Unit 1 Part 1.pptLecture 1 =Unit 1 Part 1.ppt
Lecture 1 =Unit 1 Part 1.ppt
DeeptimaanKrishnaJad
 
What Is a Database Powerpoint Presentation.pptx
What Is a Database Powerpoint Presentation.pptxWhat Is a Database Powerpoint Presentation.pptx
What Is a Database Powerpoint Presentation.pptx
graciouspezoh
 
Database system Handbook 3rd DONE Complete DBMS book Full book.pdf
Database system Handbook 3rd DONE Complete DBMS book Full book.pdfDatabase system Handbook 3rd DONE Complete DBMS book Full book.pdf
Database system Handbook 3rd DONE Complete DBMS book Full book.pdf
Bahria University Islamabad, Pakistan
 
Database system Handbook 3rd DONE Complete DBMS book Full book.pdf
Database system Handbook 3rd DONE Complete DBMS book Full book.pdfDatabase system Handbook 3rd DONE Complete DBMS book Full book.pdf
Database system Handbook 3rd DONE Complete DBMS book Full book.pdf
Bahria University Islamabad, Pakistan
 
Database system Handbook 3rd DONE Complete DBMS book Full book.pdf
Database system Handbook 3rd DONE Complete DBMS book Full book.pdfDatabase system Handbook 3rd DONE Complete DBMS book Full book.pdf
Database system Handbook 3rd DONE Complete DBMS book Full book.pdf
Bahria University Islamabad, Pakistan
 
S-VYASA STQA-1.pptx00000000000000000000000000000000
S-VYASA STQA-1.pptx00000000000000000000000000000000S-VYASA STQA-1.pptx00000000000000000000000000000000
S-VYASA STQA-1.pptx00000000000000000000000000000000
VaibhavSrivastav52
 
4rth Complete book Database systems Handbook dbms rdbms by Muhammad Sharif.pdf
4rth Complete book Database systems Handbook dbms rdbms by Muhammad Sharif.pdf4rth Complete book Database systems Handbook dbms rdbms by Muhammad Sharif.pdf
4rth Complete book Database systems Handbook dbms rdbms by Muhammad Sharif.pdf
Bahria University Islamabad, Pakistan
 
4rth Complete book Database systems Handbook dbms rdbms by Muhammad Sharif.pdf
4rth Complete book Database systems Handbook dbms rdbms by Muhammad Sharif.pdf4rth Complete book Database systems Handbook dbms rdbms by Muhammad Sharif.pdf
4rth Complete book Database systems Handbook dbms rdbms by Muhammad Sharif.pdf
Bahria University Islamabad, Pakistan
 
DBA book sql rdbms 4rth Complete book Database systems Handbook dbms rdbms by...
DBA book sql rdbms 4rth Complete book Database systems Handbook dbms rdbms by...DBA book sql rdbms 4rth Complete book Database systems Handbook dbms rdbms by...
DBA book sql rdbms 4rth Complete book Database systems Handbook dbms rdbms by...
Bahria University Islamabad, Pakistan
 
Basic of Database Management System(DBMS)
Basic of Database Management System(DBMS)Basic of Database Management System(DBMS)
Basic of Database Management System(DBMS)
anjanasharma77573
 
S-VYASA dbms111111111111111111111111111111111111111
S-VYASA dbms111111111111111111111111111111111111111S-VYASA dbms111111111111111111111111111111111111111
S-VYASA dbms111111111111111111111111111111111111111
VaibhavSrivastav52
 
Dbms notesization 2014
Dbms notesization 2014Dbms notesization 2014
Dbms notesization 2014
Dev Sanskriti Vishwavidyalaya (University)
 
Ch-1-Introduction-to-Database.pdf
Ch-1-Introduction-to-Database.pdfCh-1-Introduction-to-Database.pdf
Ch-1-Introduction-to-Database.pdf
MrjJoker1
 
Database management systems
Database management systemsDatabase management systems
Database management systems
Joel Briza
 
rdbms1-191014080818000000000000000000000000000000000
rdbms1-191014080818000000000000000000000000000000000rdbms1-191014080818000000000000000000000000000000000
rdbms1-191014080818000000000000000000000000000000000
VaibhavSrivastav52
 
Components and Advantages of DBMS
Components and Advantages of DBMSComponents and Advantages of DBMS
Components and Advantages of DBMS
Shubham Joon
 
Module 1 - Chapter1.pptx
Module 1 - Chapter1.pptxModule 1 - Chapter1.pptx
Module 1 - Chapter1.pptx
SoniaDevi15
 
What Is a Database Powerpoint Presentation.pptx
What Is a Database Powerpoint Presentation.pptxWhat Is a Database Powerpoint Presentation.pptx
What Is a Database Powerpoint Presentation.pptx
graciouspezoh
 
S-VYASA STQA-1.pptx00000000000000000000000000000000
S-VYASA STQA-1.pptx00000000000000000000000000000000S-VYASA STQA-1.pptx00000000000000000000000000000000
S-VYASA STQA-1.pptx00000000000000000000000000000000
VaibhavSrivastav52
 
4rth Complete book Database systems Handbook dbms rdbms by Muhammad Sharif.pdf
4rth Complete book Database systems Handbook dbms rdbms by Muhammad Sharif.pdf4rth Complete book Database systems Handbook dbms rdbms by Muhammad Sharif.pdf
4rth Complete book Database systems Handbook dbms rdbms by Muhammad Sharif.pdf
Bahria University Islamabad, Pakistan
 
4rth Complete book Database systems Handbook dbms rdbms by Muhammad Sharif.pdf
4rth Complete book Database systems Handbook dbms rdbms by Muhammad Sharif.pdf4rth Complete book Database systems Handbook dbms rdbms by Muhammad Sharif.pdf
4rth Complete book Database systems Handbook dbms rdbms by Muhammad Sharif.pdf
Bahria University Islamabad, Pakistan
 
DBA book sql rdbms 4rth Complete book Database systems Handbook dbms rdbms by...
DBA book sql rdbms 4rth Complete book Database systems Handbook dbms rdbms by...DBA book sql rdbms 4rth Complete book Database systems Handbook dbms rdbms by...
DBA book sql rdbms 4rth Complete book Database systems Handbook dbms rdbms by...
Bahria University Islamabad, Pakistan
 
Basic of Database Management System(DBMS)
Basic of Database Management System(DBMS)Basic of Database Management System(DBMS)
Basic of Database Management System(DBMS)
anjanasharma77573
 
S-VYASA dbms111111111111111111111111111111111111111
S-VYASA dbms111111111111111111111111111111111111111S-VYASA dbms111111111111111111111111111111111111111
S-VYASA dbms111111111111111111111111111111111111111
VaibhavSrivastav52
 
Ch-1-Introduction-to-Database.pdf
Ch-1-Introduction-to-Database.pdfCh-1-Introduction-to-Database.pdf
Ch-1-Introduction-to-Database.pdf
MrjJoker1
 
Database management systems
Database management systemsDatabase management systems
Database management systems
Joel Briza
 

More from BINJAD1 (18)

Pixel- A pixel, short for "picture element.pptx
Pixel- A pixel, short for "picture element.pptxPixel- A pixel, short for "picture element.pptx
Pixel- A pixel, short for "picture element.pptx
BINJAD1
 
Introduction to Computer Graphics or CG.ppt
Introduction to Computer Graphics or CG.pptIntroduction to Computer Graphics or CG.ppt
Introduction to Computer Graphics or CG.ppt
BINJAD1
 
2D-Transformations-Transformations are the operations applied to geometrical ...
2D-Transformations-Transformations are the operations applied to geometrical ...2D-Transformations-Transformations are the operations applied to geometrical ...
2D-Transformations-Transformations are the operations applied to geometrical ...
BINJAD1
 
2D Viewing- the window by setting a two-dimensional viewing co-ordinate syst...
2D Viewing-  the window by setting a two-dimensional viewing co-ordinate syst...2D Viewing-  the window by setting a two-dimensional viewing co-ordinate syst...
2D Viewing- the window by setting a two-dimensional viewing co-ordinate syst...
BINJAD1
 
The internet and WWW-he terms World Wide Web (WWW) and the Internet
The internet and WWW-he terms World Wide Web (WWW) and the InternetThe internet and WWW-he terms World Wide Web (WWW) and the Internet
The internet and WWW-he terms World Wide Web (WWW) and the Internet
BINJAD1
 
Introduction to Java Programming- Java Programming Tutorials for beginners
Introduction to Java Programming- Java Programming Tutorials for beginnersIntroduction to Java Programming- Java Programming Tutorials for beginners
Introduction to Java Programming- Java Programming Tutorials for beginners
BINJAD1
 
Introduction to object oriented programming.pptx
Introduction to object oriented programming.pptxIntroduction to object oriented programming.pptx
Introduction to object oriented programming.pptx
BINJAD1
 
Sum of Product or SOP and Product of Sum or POS+ Karnaugh Map or K-Map .pptx
Sum of Product or SOP and Product of Sum or POS+ Karnaugh Map or K-Map .pptxSum of Product or SOP and Product of Sum or POS+ Karnaugh Map or K-Map .pptx
Sum of Product or SOP and Product of Sum or POS+ Karnaugh Map or K-Map .pptx
BINJAD1
 
Counters-Counter is a sequential circuit.pptx
Counters-Counter is a sequential circuit.pptxCounters-Counter is a sequential circuit.pptx
Counters-Counter is a sequential circuit.pptx
BINJAD1
 
Introduction to Linux-Linux is a Unix-like
Introduction to Linux-Linux is a Unix-likeIntroduction to Linux-Linux is a Unix-like
Introduction to Linux-Linux is a Unix-like
BINJAD1
 
Tokens in php (php: Hypertext Preprocessor).pptx
Tokens in  php (php: Hypertext Preprocessor).pptxTokens in  php (php: Hypertext Preprocessor).pptx
Tokens in php (php: Hypertext Preprocessor).pptx
BINJAD1
 
Introduction to PHP (Hypertext Preprocessor).pptx
Introduction to PHP (Hypertext Preprocessor).pptxIntroduction to PHP (Hypertext Preprocessor).pptx
Introduction to PHP (Hypertext Preprocessor).pptx
BINJAD1
 
MOODLEMoodle is a free, online Learning Management system .ppt
MOODLEMoodle is a free, online Learning Management system .pptMOODLEMoodle is a free, online Learning Management system .ppt
MOODLEMoodle is a free, online Learning Management system .ppt
BINJAD1
 
The Basics and Understanding of Computer Networking.pptx
The Basics and Understanding of Computer Networking.pptxThe Basics and Understanding of Computer Networking.pptx
The Basics and Understanding of Computer Networking.pptx
BINJAD1
 
Introduction to Computer Logical Organization
Introduction to Computer Logical OrganizationIntroduction to Computer Logical Organization
Introduction to Computer Logical Organization
BINJAD1
 
HTML Forms: The HTML element represents a document section containing interac...
HTML Forms: The HTML element represents a document section containing interac...HTML Forms: The HTML element represents a document section containing interac...
HTML Forms: The HTML element represents a document section containing interac...
BINJAD1
 
HTML Tags: HTML tags are the basic building blocks of any website. They are u...
HTML Tags: HTML tags are the basic building blocks of any website. They are u...HTML Tags: HTML tags are the basic building blocks of any website. They are u...
HTML Tags: HTML tags are the basic building blocks of any website. They are u...
BINJAD1
 
01 01 Introduction to Computers.ppt
01 01 Introduction to Computers.ppt01 01 Introduction to Computers.ppt
01 01 Introduction to Computers.ppt
BINJAD1
 
Pixel- A pixel, short for "picture element.pptx
Pixel- A pixel, short for "picture element.pptxPixel- A pixel, short for "picture element.pptx
Pixel- A pixel, short for "picture element.pptx
BINJAD1
 
Introduction to Computer Graphics or CG.ppt
Introduction to Computer Graphics or CG.pptIntroduction to Computer Graphics or CG.ppt
Introduction to Computer Graphics or CG.ppt
BINJAD1
 
2D-Transformations-Transformations are the operations applied to geometrical ...
2D-Transformations-Transformations are the operations applied to geometrical ...2D-Transformations-Transformations are the operations applied to geometrical ...
2D-Transformations-Transformations are the operations applied to geometrical ...
BINJAD1
 
2D Viewing- the window by setting a two-dimensional viewing co-ordinate syst...
2D Viewing-  the window by setting a two-dimensional viewing co-ordinate syst...2D Viewing-  the window by setting a two-dimensional viewing co-ordinate syst...
2D Viewing- the window by setting a two-dimensional viewing co-ordinate syst...
BINJAD1
 
The internet and WWW-he terms World Wide Web (WWW) and the Internet
The internet and WWW-he terms World Wide Web (WWW) and the InternetThe internet and WWW-he terms World Wide Web (WWW) and the Internet
The internet and WWW-he terms World Wide Web (WWW) and the Internet
BINJAD1
 
Introduction to Java Programming- Java Programming Tutorials for beginners
Introduction to Java Programming- Java Programming Tutorials for beginnersIntroduction to Java Programming- Java Programming Tutorials for beginners
Introduction to Java Programming- Java Programming Tutorials for beginners
BINJAD1
 
Introduction to object oriented programming.pptx
Introduction to object oriented programming.pptxIntroduction to object oriented programming.pptx
Introduction to object oriented programming.pptx
BINJAD1
 
Sum of Product or SOP and Product of Sum or POS+ Karnaugh Map or K-Map .pptx
Sum of Product or SOP and Product of Sum or POS+ Karnaugh Map or K-Map .pptxSum of Product or SOP and Product of Sum or POS+ Karnaugh Map or K-Map .pptx
Sum of Product or SOP and Product of Sum or POS+ Karnaugh Map or K-Map .pptx
BINJAD1
 
Counters-Counter is a sequential circuit.pptx
Counters-Counter is a sequential circuit.pptxCounters-Counter is a sequential circuit.pptx
Counters-Counter is a sequential circuit.pptx
BINJAD1
 
Introduction to Linux-Linux is a Unix-like
Introduction to Linux-Linux is a Unix-likeIntroduction to Linux-Linux is a Unix-like
Introduction to Linux-Linux is a Unix-like
BINJAD1
 
Tokens in php (php: Hypertext Preprocessor).pptx
Tokens in  php (php: Hypertext Preprocessor).pptxTokens in  php (php: Hypertext Preprocessor).pptx
Tokens in php (php: Hypertext Preprocessor).pptx
BINJAD1
 
Introduction to PHP (Hypertext Preprocessor).pptx
Introduction to PHP (Hypertext Preprocessor).pptxIntroduction to PHP (Hypertext Preprocessor).pptx
Introduction to PHP (Hypertext Preprocessor).pptx
BINJAD1
 
MOODLEMoodle is a free, online Learning Management system .ppt
MOODLEMoodle is a free, online Learning Management system .pptMOODLEMoodle is a free, online Learning Management system .ppt
MOODLEMoodle is a free, online Learning Management system .ppt
BINJAD1
 
The Basics and Understanding of Computer Networking.pptx
The Basics and Understanding of Computer Networking.pptxThe Basics and Understanding of Computer Networking.pptx
The Basics and Understanding of Computer Networking.pptx
BINJAD1
 
Introduction to Computer Logical Organization
Introduction to Computer Logical OrganizationIntroduction to Computer Logical Organization
Introduction to Computer Logical Organization
BINJAD1
 
HTML Forms: The HTML element represents a document section containing interac...
HTML Forms: The HTML element represents a document section containing interac...HTML Forms: The HTML element represents a document section containing interac...
HTML Forms: The HTML element represents a document section containing interac...
BINJAD1
 
HTML Tags: HTML tags are the basic building blocks of any website. They are u...
HTML Tags: HTML tags are the basic building blocks of any website. They are u...HTML Tags: HTML tags are the basic building blocks of any website. They are u...
HTML Tags: HTML tags are the basic building blocks of any website. They are u...
BINJAD1
 
01 01 Introduction to Computers.ppt
01 01 Introduction to Computers.ppt01 01 Introduction to Computers.ppt
01 01 Introduction to Computers.ppt
BINJAD1
 
Ad

Recently uploaded (20)

Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdfCrypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
 
Enabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FMEEnabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FME
Safe Software
 
Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementaryMurdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
 
Cisco ISE Performance, Scalability and Best Practices.pdf
Cisco ISE Performance, Scalability and Best Practices.pdfCisco ISE Performance, Scalability and Best Practices.pdf
Cisco ISE Performance, Scalability and Best Practices.pdf
superdpz
 
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and ImplementationAI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
Christine Shepherd
 
Ben Blair - Operating Safely in a Vibe Coding World
Ben Blair - Operating Safely in a Vibe Coding WorldBen Blair - Operating Safely in a Vibe Coding World
Ben Blair - Operating Safely in a Vibe Coding World
AWS Chicago
 
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Safe Software
 
Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025
Safe Software
 
Oracle Cloud Infrastructure AI Foundations
Oracle Cloud Infrastructure AI FoundationsOracle Cloud Infrastructure AI Foundations
Oracle Cloud Infrastructure AI Foundations
VICTOR MAESTRE RAMIREZ
 
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
angelo60207
 
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOMEstablish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Anchore
 
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdfArtificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
 
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Anish Kumar
 
Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025
Safe Software
 
Providing an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME FlowProviding an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME Flow
Safe Software
 
Oracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI ProfessionalOracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI Professional
VICTOR MAESTRE RAMIREZ
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too LateKubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...
“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...
“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...
Edge AI and Vision Alliance
 
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
NTT DATA Technology & Innovation
 
Oracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization ProgramOracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization Program
VICTOR MAESTRE RAMIREZ
 
Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdfCrypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
 
Enabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FMEEnabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FME
Safe Software
 
Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementaryMurdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
 
Cisco ISE Performance, Scalability and Best Practices.pdf
Cisco ISE Performance, Scalability and Best Practices.pdfCisco ISE Performance, Scalability and Best Practices.pdf
Cisco ISE Performance, Scalability and Best Practices.pdf
superdpz
 
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and ImplementationAI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
Christine Shepherd
 
Ben Blair - Operating Safely in a Vibe Coding World
Ben Blair - Operating Safely in a Vibe Coding WorldBen Blair - Operating Safely in a Vibe Coding World
Ben Blair - Operating Safely in a Vibe Coding World
AWS Chicago
 
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Safe Software
 
Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025
Safe Software
 
Oracle Cloud Infrastructure AI Foundations
Oracle Cloud Infrastructure AI FoundationsOracle Cloud Infrastructure AI Foundations
Oracle Cloud Infrastructure AI Foundations
VICTOR MAESTRE RAMIREZ
 
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
angelo60207
 
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOMEstablish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Anchore
 
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdfArtificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
 
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Anish Kumar
 
Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025
Safe Software
 
Providing an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME FlowProviding an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME Flow
Safe Software
 
Oracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI ProfessionalOracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI Professional
VICTOR MAESTRE RAMIREZ
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too LateKubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...
“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...
“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...
Edge AI and Vision Alliance
 
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
NTT DATA Technology & Innovation
 
Oracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization ProgramOracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization Program
VICTOR MAESTRE RAMIREZ
 
Ad

Structured Query Language (SQL)- standard Database language

  • 2. 1.0 What is Data? • In simple words, data can be facts related to any object in consideration. • For example, your name, age, height, weight, etc. are some data related to you. • A picture, image, file, pdf, etc. can also be considered data.
  • 3. 1.0 What is Data? … • We all are familiar with Social websites like Facebook & Instagram, E-Commerce websites like Amazon & SnapDeal, Banking websites like Barclays & HDFC or any Education website like ToolsQA, all these websites have a humongous amount of data stored in it. • So what is Data? • Data is any sort of information which is stored in computer memory. • This information can later be used for a website, an application or any other client to store for future purpose. • The most common information is User information in the form of user personal, address and banking information.
  • 4. 1.0 What is Data? … • Let’s consider Facebook, it stores our personal data, images, posts, comments and many more things. • Banking application also stores user data, their transactions details, funds summary etc. • All this information is data, but when it put together and store in a structural way, it becomes informational data. • But, how do these applications or websites get data? • When you post a status on Facebook, perform a banking transaction online or upload a selfie on Instagram, you are actually sending data to the site or to be precise their server. • So, we can say any information transmitted or transferred is actually data. • Server filter out the necessary data and stores it in Database (DB).
  • 5. 1.1 Data, Information, and Knowledge • Data are the raw bits and pieces of information with no context. • If I told you, “15, 23, 14, 85,” you would not have learned anything. • But I would have given you data. • Data can be quantitative or qualitative. • Quantitative data is numeric, the result of a measurement, count, or some other mathematical calculation. • Qualitative data is descriptive. “Ruby Red,” the color of a 2013 Ford Focus, is an example of qualitative data. • A number can be qualitative too: if I tell you my favorite number is 5, that is qualitative data because it is descriptive, not the result of a measurement or mathematical calculation.
  • 6. 1.1 Data, Information, and Knowledge…
  • 7. 1.1 Data, Information, and Knowledge… • By itself, data is not that useful. • To be useful, it needs to be given context. • Returning to the example above, if I told you that “15, 23, 14, and 85″ are the numbers of students that had registered for upcoming classes, that would be information. • By adding the context – that the numbers represent the count of students registering for specific classes – I have converted data into information. • Once we have put our data into context, aggregated and analyzed it, we can use it to make decisions for our organization. • We can say that this consumption of information produces knowledge. • This knowledge can be used to make decisions, set policies, and even spark innovation. • The final step up the information ladder is the step from knowledge (knowing a lot about a topic) to wisdom. • We can say that someone has wisdom when they can combine their knowledge and experience to produce a deeper understanding of a topic. • It often takes many years to develop wisdom on a particular topic, and requires patience.
  • 8. 1.1 Examples of Data • Almost all software programs require data to do anything useful. • For example, if you are editing a document in a word processor such as Microsoft Word, the document you are working on is the data. • The word-processing software can manipulate the data: create a new document, duplicate a document, or modify a document. • Some other examples of data are: an MP3 music file, a video file, a spreadsheet, a web page, and an e-book. • In some cases, such as with an e-book, you may only have the ability to read the data.
  • 9. 1.2 What is a Database (DB) ? • The goal of many information systems is to transform data into information in order to generate knowledge that can be used for decision making. • In order to do this, the system must be able to take data, put the data into context, and provide tools for aggregation and analysis. • A database is designed for just such a purpose. • A database is an organized collection of related information. • It is an organized collection, because in a database, all data is described and associated with other data. • All information in a database should be related as well; separate databases should be created to manage unrelated information. • For example, a database that contains information about students should not also hold information about company stock prices. • Databases are not always digital – a filing cabinet, for instance, might be considered a form of database. • For the purposes of this text, we will only consider digital databases.
  • 10. 1.2 What is a Database (DB) ?… • A database is a systematic collection of data. • They support electronic storage and manipulation of data. • Databases make data management easy. • Let us discuss a few examples: • An online telephone directory uses a database to store data of people, phone numbers, other contact details. • Your electricity service provider uses a database to manage billing, client-related issues, handle fault data, etc. • Let us also consider Facebook. • It needs to store, manipulate, and present data related to members, their friends, member activities, messages, advertisements, and a lot more. • We can provide a countless number of examples for the usage of databases.
  • 11. 1.2 What is a Database (DB) ?… • So what is a Database? • Is it a random collection of stuff all squeezed in together? • No, Database (DB) are organized, they have a structure, and all the data they store it fits into that structure. • More specifically, a database is an electronic system that allows data to be stored, easily accessed, manipulated and updated. • So, we just saw the definition of databases but where in real life can we see such things? • Well, we all are well aware of things like a telephone directory. • Well, phonebook/telephone directory actually contains the name of people arranged in order of their last names. • So, we are able to store data and search it efficiently using the last name of the person, like it’s really easy if I ask you to search for Tyagi, Vishu.
  • 12. 1.2 What is a Database (DB) ?… • But an issue arrives if I ask you to search for every contact with the first name Martin. • The issue here is, names are stored according to last names so searching for the first name is a lot trickier. • So, a database is made up of two components mainly, data and a meaningful method for accessing and manipulating data. • Without these two, a database is just a random set of data. • A more precise example of a database can be a dictionary, which stores a large quantity of data as Key-Value pairs. • At the same time, it also has a meaningful method to access data using the Key. • Databases are quite similar to spreadsheets as they are mostly made up of tables which contain rows and columns like a spreadsheet. • A database needs to be hosted or created on some special database platform, some of the famous Database platforms are: • PostgreSQL • MySQL • Microsoft Access • SQLite • We know that when we use any software, like an app, data is either added to the database, updated according to the action or pulled as per the action we perform. • But, the computer must have something to perform such action too. • A software which can perform the various operations on databases is known as Database Management System (DBMS).
  • 13. 1.2 What is a Database (DB) ?… • As the name suggests, a database is a place where all the data gets stored in a structured format. • It helps the users to easily access, manage and update the required information. • So, in layman terms you can understand, a database as a big container wherein all the information about a website, or an application is stored in a structured format. • For example, a company can have various details of employees, such as name, empID, email, blood group, salary, and so on. • All these details can be stored in a database with the name “Employee” in a structured format such as tables, hierarchy, etc. • In any organization, be it a startup or a hyper-growth company, many databases can be present, but it is very important to manage those databases in a proper manner. • So, next in this article let us understand how to manage these databases.
  • 14. 2.0 Database Management Systems (DBMS) • There is no doubt in the fact that humongous amounts of data get generated on a daily basis from various applications, business sites in different formats. • But, how do you think, we can handle data present in various formats and generate useful insights. • Well, to do that, we need the database management systems(DBMS).
  • 15. 2.1 What is DBMS ? … • DBMS or Database Management System is a software application used to access, create, and manage databases. • With the help of DBMS, you can easily create, retrieve and update data in databases. • A DBMS consists of a group of commands to manipulate the database and acts as an interface between the end-users and the database.
  • 16. 2.1 What is DBMS? … • Database Management Systems also aims to facilitate an overview of the databases, by providing a variety of administrative operations such as tuning, performance monitoring, and backup recovery. • Database Management Systems allows users to do the following:  Define Data – Allows the users to create, modify and delete the definitions which define the organization of the database.  Update Data – Provides access to the users to insert, modify and delete data from the database.  Retrieve Data – Allows the users to retrieve data from the database based on the requirement.  Administration of users – Registers the users and monitors their action, enforces data security, maintains data integrity, monitors performance and deals with concurrency control.
  • 17. 2.2 Example of a DBMS • Let us see a simple example of a university database. • This database is maintaining information concerning students, courses, and grades in a university environment. • The database is organized as five files:  The STUDENT file stores data of each student  The COURSE file stores contain data on each course.  The SECTION stores the information about sections in a particular course.  The GRADE file stores the grades which students receive in the various sections  The TUTOR file contains information about each professor. • To define a database system: o We need to specify the structure of the records of each file by defining the different types of data elements to be stored in each record. o We can also use a coding scheme to represent the values of a data item. o Basically, your Database will have 5 tables with a foreign key defined amongst the various tables.
  • 18. 2.3 History of DBMS • Here, are the important landmarks from the history:  1960 - Charles Bachman designed first DBMS system  1970 - Codd introduced IBM'S Information Management System (IMS)  1976- Peter Chen coined and defined the Entity-relationship model also know as the ER model  1980 - Relational Model becomes a widely accepted database component  1985- Object-oriented DBMS develops.  1990s- Incorporation of object-orientation in relational DBMS.  1991- Microsoft ships MS access, a personal DBMS and that displaces all other personal DBMS products.  1995: First Internet database applications  1997: XML applied to database processing. Many vendors begin to integrate XML into DBMS products.
  • 19. 2.4 Characteristics of DBMS • The following are a few characteristics of DBMS:  Provides security and removes redundancy  Self-describing nature of a database system  Insulation between programs and data abstraction  Support of multiple views of the data  Sharing of data and multiuser transaction processing  DBMS allows entities and relations among them to form tables.  It follows the ACID concept (Atomicity, Consistency, Isolation, and Durability).  DBMS supports multi-user environment that allows users to access and manipulate data in parallel.
  • 20. 2.4 DBMS vs. Flat File DBMS Flat File Management System • Multi-user access • It does not support multi-user access • Design to fulfill the need for small and large businesses • It is only limited to smaller DBMS system. • Remove redundancy and Integrity • Redundancy and Integrity issues
  • 21. 2.5 Users in a DBMS environment Component Name Task Application Programmers • The Application programmers write programs in various programming languages to interact with databases. Database Administrators • Database Admin is responsible for managing the entire DBMS system. • He/She is called Database admin or DBA. End-Users • The end users are the people who
  • 22. 2.6 Popular DBMS Software • Here, is the list of some popular DBMS system:  MySQL  Microsoft Access  Oracle  PostgreSQL  dBASE  FoxPro  SQLite  IBM DB2  LibreOffice Base  MariaDB  Microsoft SQL Server etc.
  • 23. 2.7 Application of DBMS Sector Use of DBMS Banking •For customer information, account activities, payments, deposits, loans, etc. Airlines •For reservations and schedule information. Universitie s •For student information, course registrations, colleges and grades. Telecommu nication •It helps to keep call records, monthly bills, maintaining balances, etc. Finance •For storing information about stock, sales, and purchases of financial instruments like stocks and bonds.
  • 24. 2.8 Types of DBMS • Four Types of DBMS systems are:  Hierarchical database  Network database  Relational database  Object-Oriented database
  • 25. 2.8 Types of DBMS 1) Hierarchical DBMS • In a Hierarchical database, model data is organized in a tree-like structure. • Data is Stored Hierarchically (top down or bottom up) format. • Data is represented using a parent-child relationship. • In Hierarchical DBMS parent may have many children, but children have only one parent. 2) Network Model • The network database model allows each child to have multiple parents. • It helps you to address the need to model more complex relationships like as the orders/parts many-to-many relationship. • In this model, entities are organized in a graph which can be accessed through several paths.
  • 26. 2.8 Types of DBMS 3) Relational model • Relational DBMS is the most widely used DBMS model because it is one of the easiest. • This model is based on normalizing data in the rows and columns of the tables. • Relational model stored in fixed structures and manipulated using SQL. 4) Object-Oriented Model • In Object-oriented Model data stored in the form of objects. • The structure which is called classes which display data within it. • It defines a database as a collection of objects which stores both data members values and operations.
  • 27. 2.9 Advantages of DBMS  DBMS offers a variety of techniques to store & retrieve data  DBMS serves as an efficient handler to balance the needs of multiple applications using the same data  Uniform administration procedures for data  Application programmers never exposed to details of data representation and storage.  A DBMS uses various powerful functions to store and retrieve data efficiently.  Offers Data Integrity and Security  The DBMS implies integrity constraints to get a high level of protection against prohibited access to data.  A DBMS schedules concurrent access to the data in such a manner that only one user can access the same data at a time  Reduced Application Development Time
  • 28. 2.10 Disadvantages of DBMS  Cost of Hardware and Software of a DBMS is quite high which increases the budget of your organization.  Most database management systems are often complex systems, so the training for users to use the DBMS is required.  In some organizations, all data is integrated into a single database which can be damaged because of electric failure or database is corrupted on the storage media  Use of the same program at a time by many users sometimes lead to the loss of some data.  DBMS can't perform sophisticated calculations
  • 29. 2.11 When not to use a DBMS system? • Although, DBMS system is useful. • It is still not suited for specific task mentioned below: • Not recommended when you do not have the budget or the expertise to operate a DBMS. • In such cases, Excel/CSV/Flat Files could do just fine.
  • 30. 3.0 DDL, DML, DCL, and TCL Commands • Structured Query Language(SQL) as we all know is the database language by the use of which we can perform certain operations on the existing database and also we can use this language to create a database. • SQL uses certain commands like Create, Drop, Insert etc. to carry out the required tasks. • These SQL commands are mainly categorized into four categories as: 1) DDL – Data Definition Language 2) DML – Data Manipulation Language 3) DCL – Data Control Language 4) TCL – Transaction Control Language
  • 31. 3.0 DDL, DML, DCL, and TCL Commands …
  • 32. 3.1 DDL Commands • DDL is short name of Data Definition Language, which deals with database schemas and descriptions, of how the data should reside in the database.  CREATE - to create a database and its objects like (table, index, views, store procedure, function, and triggers)  ALTER - alters the structure of the existing database  DROP - delete objects from the database  TRUNCATE - remove all records from a table, including all spaces allocated for the records are removed  COMMENT - add comments to the data dictionary  RENAME - rename an object
  • 33. 3.1 DDL Commands : Creating a Database • To create a database in RDBMS, create command is used. • Following is the syntax, • Example for creating Database • The above command will create a database named Test, which will be an empty schema without any table. • To create tables in this newly created database, we can again use the create command. CREATE DATABASE <DB_NAME>; CREATE DATABASE Test;
  • 34. 3.1 DDL Commands : Creating a Table • Create command can also be used to create tables. • Now when we create a table, we have to specify the details of the columns of the tables too. • We can specify the names and datatypes of various columns in the create command itself. • Following is the syntax, • Create table command will tell the database system to create a new table with the given table name and column information. CREATE TABLE <TABLE_NAME> ( column_name1 datatype1, column_name2 datatype2, column_name3 datatype3, column_name4 datatype4 );
  • 35. creating Table • The above command will create a new table with name Student in the current database with 3 columns, namely student_id, name and age. • Where the column student_id will only store integer, name will hold upto 100 characters and age will again store only integer value. CREATE TABLE Student ( student_id INT, name VARCHAR(100), age INT );
  • 36. Table … • If you are currently not logged into your database in which you want to create the table then you can also add the database name along with table name, using a dot operator . • For example, if we have a database with name Test and we want to create a table Student in it, then we can do so using the following query: CREATE TABLE Test.Student ( student_id INT, name VARCHAR(100), age INT );
  • 37. 3.1 DDL Commands : Most commonly used datatypes for Table columns Dataty pe Use INT used for columns which will store integer values. FLOAT used for columns which will store float values. DOUBL E used for columns which will store float values. VARCH AR used for columns which will be used to store characters and integers, basically a string. CHAR used for columns which will store char
  • 38. 3.2 DDL Commands : ALTER command • alter command is used for altering the table structure, such as, to add a column to existing table to rename any existing column to change datatype of any column or to modify its size. to drop a column from the table.
  • 39. 3.2 DDL Commands : ALTER command : Add a new Column • Using ALTER command we can add a column to any existing table. • Following is the syntax, • Here is an Example for this, • The above command will add a new column address to the table student, which will hold data of type varchar which is nothing but string, of length 200. ALTER TABLE table_name ADD ( column_name datatype ); ALTER TABLE student ADD ( address VARCHAR(200) );
  • 40. 3.2 DDL Commands : ALTER command : Add multiple new Columns • Using ALTER command we can even add multiple new columns to any existing table. • Following is the syntax, • Here is an Example for this, • The above command will add three new columns to the student table. ALTER TABLE table_name ADD ( column_name1 datatype1, column-name2 datatype2, column-name3 datatype3 ); ALTER TABLE student ADD ( father_name VARCHAR(60), mother_name VARCHAR(60), dob DATE );
  • 41. 3.2 DDL Commands : ALTER command : Add Column with default value • ALTER command can add a new column to an existing table with a default value too. • The default value is used when no value is inserted in the column. • Following is the syntax, • Here is an Example for this, • The above command will add a new column with a preset default value to the table student. ALTER TABLE table_name ADD ( column-name1 datatype1 DEFAULT some_value ); ALTER TABLE student ADD ( dob DATE DEFAULT '01-Jan-99' );
  • 42. 3.2 DDL Commands : ALTER command : Modify an existing Column • ALTER command can also be used to modify data type of any existing column. • Following is the syntax, • Here is an Example for this, • Remember we added a new column address in the beginning? • The above command will modify the address column of the student table, to now hold up to 300 characters. ALTER TABLE table_name modify ( column_name datatype ); ALTER TABLE student MODIFY ( address varchar(300) );
  • 43. 3.2 DDL Commands : ALTER command : Rename a Column • Using ALTER command you can rename an existing column. • Following is the syntax, • Here is an example for this, • The above command will rename address column to location. ALTER TABLE table_name RENAME old_column_name TO new_column_name; ALTER TABLE student RENAME address TO location;
  • 44. 3.2 DDL Commands : ALTER command : Drop a Column • ALTER command can also be used to drop or remove columns. • Following is the syntax, • Here is an example for this, • The above command will drop the address column from the table student. ALTER TABLE table_name DROP ( column_name ); ALTER TABLE student DROP ( address );
  • 45. Rename a Table TRUNCATE command • TRUNCATE command removes all the records from a table. • But this command will not destroy the table's structure. • When we use TRUNCATE command on a table its (auto-increment) primary key is also initialized. • Following is its syntax, • Here is an example explaining it, • The above query will delete all the records from the table student. • In DML commands, we will study about the DELETE command which is also more or less same as the TRUNCATE command. TRUNCATE TABLE table_name TRUNCATE TABLE student;
  • 46. 3.3 DDL Commands : DROP command • DROP command completely removes a table from the database. • This command will also destroy the table structure and the data stored in it. • Following is its syntax, • Here is an example explaining it, • The above query will delete the Student table completely. • It can also be used on Databases, to delete the complete database. • For example, to drop a database, • The above query will drop the database with name Test from the system. DROP TABLE table_name DROP TABLE student; DROP DATABASE Test;
  • 47. 3.3 DDL Commands : RENAME query • RENAME command is used to set a new name for any existing table. • Following is the syntax, • Here is an example explaining it. • The above query will rename the table student to students_info RENAME TABLE old_table_name to new_table_name RENAME TABLE student to students_info;
  • 48. 3.4 SQL: Comments • Comments are used to explain sections of SQL statements, or to prevent execution of SQL statements. • These comments can appear on a single line or span across multiple lines. • There are two types that you can use to create a comment in SQL. 1. Single Line Comment (- -) 2. Multiple Lines Comment (/* */)
  • 49. 3.4 SQL: Comments : Single Line Comment (- -) Syntax Using -- symbol • The syntax for creating a SQL comment using the -- symbol in SQL Server is: Example - Comment on a Single Line -- comment goes here SELECT employee_id, last_name -- Author: MMC MNTDY FROM employees;
  • 50. (/* */) Syntax Using /* and */ symbols • The syntax for creating a SQL comment using /* and */ symbols in SQL Server (Transact-SQL) is: • In SQL Server, a comment that starts with /* symbol and ends with */ and can be anywhere in your SQL statement. • This method of commenting can span several lines within your SQL. /* comment goes here */
  • 51. (/* */) … Example - Comment on a Multiple Lines • Let's look at a SQL comment example that shows a SQL comment on its own line: • Here is a SQL comment that appears in the middle of the line: • Here is a SQL comment that appears at the end of the line: SELECT employee_id, last_name /* Author: MMC MNTDY*/ FROM employees; SELECT /* Author: MMC MNTDY*/ employee_id, last_name FROM employees; SELECT employee_id, last_name /* Author: MMC MNTDY Purpose: To show a comment that spans multiple lines in your SQL statement. */ FROM employees;
  • 52. 4.0 DML Commands • DML is short name of Data Manipulation Language which deals with data manipulation and includes most common SQL statements such SELECT, INSERT, UPDATE, DELETE, etc., and it is used to store, modify, retrieve, delete and update data in a database.  SELECT - retrieve data from a database  INSERT - insert data into a table  UPDATE - updates existing data within a table  DELETE - Delete all records from a database table  MERGE - UPSERT operation (insert or update)  CALL - call a PL/SQL or Java subprogram  EXPLAIN PLAN - interpretation of the data access path  LOCK TABLE - concurrency Control
  • 53. command • Data Manipulation Language (DML) statements are used for managing data in database. • DML commands are not auto-committed. • It means changes made by DML command are not permanent to database, it can be rolled back. • Talking about the Insert command, whenever we post a Tweet on Twitter, the text is stored in some table, and as we post a new tweet, a new record gets inserted in that table.
  • 54. command… • Insert command is used to insert data into a table. • Following is its general syntax, • Lets see an example, • Consider a table student with the following fields. • The above command will insert a new record into student table. INSERT INTO table_name VALUES(data1, data2, ...) s_id name age INSERT INTO student VALUES(101, 'Adam', 15); s_id name age 101 Adam 15
  • 55. 4.1 DML Commands : Insert value into only specific columns • We can use the INSERT command to insert values for only some specific columns of a row. • We can specify the column names along with the values to be inserted like this, • The above SQL query will only insert id and name values in the newly inserted record. INSERT INTO student(id, name) values(102, 'Alex');
  • 56. 4.1 DML Commands : Insert NULL value to a column • Both the statements below will insert NULL value into age column of the student table. Or, • The above command will insert only two column values and the other column is set to null. INSERT INTO student(id, name) values(102, 'Alex'); INSERT INTO Student VALUES(102,'Alex', null); S_id S_Name age 101 Adam 15 102 Alex
  • 57. 4.1 DML Commands : Insert Default value to a column • Suppose the column age in our tabel has a default value of 14. • Also, if you run the below query, it will insert default value into the age column, whatever the default value may be. INSERT INTO Student VALUES(103,'Chris', default) INSERT INTO Student VALUES(103,'Chris') S_id S_Name age 101 Adam 15 102 Alex 103 chris 14
  • 58. 4.2 DML Commands : SELECT SQL Query • SELECT query is used to retrieve data from a table. • It is the most used SQL query. • We can retrieve complete table data, or partial by specifying conditions using the WHERE clause. Syntax of SELECT query • SELECT query is used to retieve records from a table. • We can specify the names of the columns which we want in the resultset. SELECT column_name1, column_name2, column_name3, ... column_nameN FROM table_name;
  • 59. 4.2 DML Commands : SELECT SQL Query Time for an Example : Consider the following student table, • The above query will fetch information of s_id, name and age columns of the student table and display them, • As you can see the data from address column is absent, because we did not specif it in our SELECT query. SELECT s_id, name, age FROM student; s_id name age address 101 Adam 15 Chennai 102 Alex 18 Delhi 103 Abhi 17 Banglore 104 Ankit 22 Mumbai s_id Name age 101 Adam 15 102 Alex 18 103 Abhi 17 104 Ankit 22
  • 60. 4.2 DML Commands : SELECT SQL Query - Select all records from a table • A special character asterisk * is used to address all the data(belonging to all columns) in a query. • SELECT statement uses * character to retrieve all records from a table, for all the columns. • The above query will show all the records of student table, that means it will show complete dataset of the table. SELECT * FROM student; s_id name age address 101 Adam 15 Chennai 102 Alex 18 Delhi 103 Abhi 17 Banglore 104 Ankit 22 Mumbai
  • 61. 4.2 DML Commands : SELECT SQL Query - Select a particular record based on a condition • We can use the WHERE clause to set a condition, • The above query will return the following result, SELECT * FROM student WHERE name = 'Abhi'; 103 Abhi 17 Banglore
  • 62. 4.2 DML Commands : SELECT SQL Query - Performing Simple Calculations using SELECT Query • Consider the following employee table. • Here is our SELECT query, • The above command will display a new column in the result, with 3000 added into existing salaries of the employees. • So you can also perform simple mathematical operations on the data too using the SELECT query to fetch data from table. SELECT eid, name, salary+3000 FROM employee; eid name age salary 101 Adam 26 5000 102 Ricky 42 8000 103 Abhi 25 10000 104 Rohan 22 5000 eid name salary+3000 101 Adam 8000 102 Ricky 11000 103 Abhi 13000 104 Rohan 8000
  • 63. 4.3 DML Commands : Using UPDATE SQL command • Let's take an example of a real-world problem. • These days, Facebook provides an option for Editing your status update, how do you think it works? • Yes, using the Update SQL command. • Let's learn about the syntax and usage of the UPDATE command. • UPDATE command is used to update any record of data in a table. • Following is its general syntax, • WHERE is used to add a condition to any SQL query. UPDATE table_name SET column_name = new_value WHERE some_condition;
  • 64. 4.3 DML Commands : Using UPDATE SQL command … • Lets take a sample table student, • In the above statement, if we do not use the WHERE clause, then our update query will update age for all the columns of the table to 18. UPDATE student SET age=18 WHERE student_id=102; student_id name age 101 Adam 15 102 Alex 103 chris 14 S_id S_Name age 101 Adam 15 102 Alex 18 103 chris 14
  • 65. 4.3 DML Commands : Using UPDATE SQL command … Updating Multiple Columns • We can also update values of multiple columns using a single UPDATE statement. • The above command will update two columns of the record which has s_id 103. UPDATE student SET name='Abhi', age=17 where s_id=103; s_id name age 101 Adam 15 102 Alex 18 103 Abhi 17
  • 66. 4.3 DML Commands : Using UPDATE SQL command … Incrementing Integer Value • When we have to update any integer value in a table, then we can fetch and update the value in the table in a single statement. • For example, if we have to update the age column of student table every year for every student, then we can simply run the following UPDATE statement to perform the following operation: • As you can see, we have used age = age + 1 to increment the value of age by 1. • NOTE: This style only works for integer values. UPDATE student SET age = age+1;
  • 67. 4.4 DML Commands : Using DELETE SQL command • When you ask any question in Study tonight's Forum it gets saved into a table. • And using the Delete option, you can even delete a question asked by you. • How do you think that works? • Yes, using the Delete DML command. • Let's study about the syntax and the usage of the Delete command. • DELETE command is used to delete data from a table. • Following is its general syntax, DELETE FROM table_name;
  • 68. 4.4 DML Commands : Using DELETE SQL command … • Let's take a sample table student: Delete all Records from a Table • The above command will delete all the records from the table student. DELETE FROM student; s_id name age 101 Adam 15 102 Alex 18 103 Abhi 17
  • 69. 4.4 DML Commands : Using DELETE SQL command … Delete a particular Record from a Table • In our student table if we want to delete a single record, we can use the WHERE clause to provide a condition in our DELETE statement. • The above command will delete the record where s_id is 103 from the table student. DELETE FROM student WHERE s_id=103;
  • 70. 4.4 DML Commands : Using DELETE SQL command … Isn't DELETE same as TRUNCATE • TRUNCATE command is different from DELETE command. • The delete command will delete all the rows from a table whereas truncate command not only deletes all the records stored in the table, but it also re- initializes the table(like a newly created table). • For eg: If you have a table with 10 rows and an auto_increment primary key, and if you use DELETE command to delete all the rows, it will delete all the rows, but will not re-initialize the primary key, hence if you will insert any row after using the DELETE command, the auto_increment primary key will start from 11. • But in case of TRUNCATE command, primary key is re-initialized, and it will again start from 1.
  • 71. 5.0 TCL Commands • Transaction Control Language(TCL) commands are used to manage transactions in the database. • These are used to manage the changes made to the data in a table by DML statements. • It also allows statements to be grouped together into logical transactions • These are-  Commit,  Rollback and  Savepoint
  • 72. 5.1 TCL Commands : COMMIT command • COMMIT command is used to permanently save any transaction into the database. • When we use any DML command like INSERT, UPDATE or DELETE, the changes made by these commands are not permanent, until the current session is closed, the changes made by these commands can be rolled back. • To avoid that, we use the COMMIT command to mark the changes as permanent. • Following is commit command's syntax, COMMIT;
  • 73. 5.2 TCL Commands : SAVEPOINT command… • SAVEPOINT command is used to temporarily save a transaction so that you can rollback to that point whenever required. • Following is savepoint command's syntax, • In short, using this command we can name the different states of our data in any table and then rollback to that state using the ROLLBACK command whenever required. SAVEPOINT savepoint_name;
  • 74. 5.3 TCL Commands : ROLLBACK command • This command restores the database to last commited state. • It is also used with SAVEPOINT command to jump to a savepoint in an ongoing transaction. • If we have used the UPDATE command to make some changes into the database, and realise that those changes were not required, then we can use the ROLLBACK command to rollback those changes, if they were not commited using the COMMIT command. • Following is rollback command's syntax, ROLLBACK TO savepoint_name;
  • 75. 5.4 TCL Commands : Examples Using Savepoint and Rollback • Following is the table class, • Lets use some SQL queries on the above table and see the results. id name 1 Abhi 2 Arunima 4 Alex INSERT INTO class VALUES(5, 'Rahul'); COMMIT; UPDATE class SET name = 'Abhijit' WHERE id = '5'; SAVEPOINT A; INSERT INTO class VALUES(6, ‘Ameya'); SAVEPOINT B; INSERT INTO class VALUES(7, 'Bravo'); SAVEPOINT C; SELECT * FROM class;
  • 76. 5.4 TCL Commands : Examples … • NOTE: SELECT statement is used to show the data stored in the table. • The resultant table will look like, id name 1 Abhi 2 Arunima 4 Alex 5 Abhijit 6 Ameya 7 Bravo
  • 77. 5.4 TCL Commands : Examples … • Now let's use the ROLLBACK command to roll back the state of data to the savepoint B. • Now our class table will look like, ROLLBACK TO B; SELECT * FROM class; id name 1 Abhi 2 Arunima 4 Alex 5 Abhijit 6 Ameya
  • 78. 5.4 TCL Commands : Examples … • Now let's again use the ROLLBACK command to roll back the state of data to the savepoint A • Now the table will look like, ROLLBACK TO A; SELECT * FROM class; id name 1 Abhi 2 Arunima 4 Alex 5 Abhijit
  • 79. 4.3 Using the WHERE SQL clause • WHERE clause is used to specify/apply any condition while retrieving, updating or deleting data from a table. • This clause is used mostly with SELECT, UPDATE and DELETE query. • When we specify a condition using the WHERE clause then the query executes only for those records for which the condition specified by the WHERE clause is true. Syntax for WHERE clause • Here is how you can use the WHERE clause with a DELETE statement, or any other statement, • The WHERE clause is used at the end of any SQL query, to specify a condition for execution. DELETE FROM table_name WHERE [condition];
  • 80. 4.3 Using the WHERE SQL clause … • Time for an Example : Consider a table student, • Now we will use the SELECT statement to display data of the table, based on a condition, which we will add to our SELECT query using WHERE clause. • Let's write a simple SQL query to display the record for student with s_id as 101. • Following will be the result of the above query. SELECT s_id, name, age, address FROM student WHERE s_id = 101; s_id name age address 101 Adam 15 Chennai 102 Alex 18 Delhi 103 Abhi 17 Banglore 104 Ankit 22 Mumbai s_id name age address 101 Adam 15 Noida
  • 81. 4.3 Using the WHERE SQL clause … Applying condition on Text Fields • In the above example we have applied a condition to an integer value field, but what if we want to apply the condition on name field. • In that case we must enclose the value in single quote ' ‘. • Some databases even accept double quotes, but single quotes is accepted by all. • Following will be the result of the above query. SELECT s_id, name, age, address FROM student WHERE name = 'Adam'; s_id name age address 101 Adam 15 Noida
  • 82. 4.3 Using the WHERE SQL clause: Operators for WHERE clause condition Operator Description = Equal to != Not Equal to < Less than > Greater than <= Less than or Equal to >= Greate than or Equal to BETWEEN Between a specified range of values LIKE This is used to search for a pattern in value. IN In a given set of values
  • 83. 5.0 SQL LIKE clause • LIKE clause is used in the condition in SQL query with the WHERE clause. • LIKE clause compares data with an expression using wildcard operators to match pattern given in the condition. Wildcard operators • There are two wildcard operators that are used in LIKE clause. • Percent sign %: represents zero, one or more than one character. • Underscore sign _: represents only a single character.
  • 84. 5.0 SQL LIKE clause: Example • Consider the following Student table. • The above query will return all records where s_name starts with character 'A’. SELECT * FROM Student WHERE s_name LIKE 'A%'; s_id s_Name age 101 Arunima 15 102 Alex 18 103 Abhi 17 s_id s_Name age 101 Arunima 15 102 Alex 18 103 Abhi 17
  • 85. 8.0 SQL Aggregate Functions • SQL aggregation function is used to perform the calculations on multiple rows of a single column of a table. • It returns a single value. • It is also used to summarize the data.
  • 86. 8.0 Why use Aggregate Functions ? • From a business perspective, different organization levels have different information requirements. • Top levels managers are usually interested in knowing whole figures and not necessary the individual details. • Aggregate functions allow us to easily produce summarized data from our database. • For instance, from our myflix database , management may require following reports • Least rented movies. • Most rented movies. • Average number that each movie is rented out in a month. • We easily produce above reports using aggregate functions.
  • 87. 8.0 Types of SQL Aggregate Functions …
  • 88. FUNCTION • Count returns the number of rows present in the table either based on some condition or without condition. • Its general syntax is, SELECT COUNT(column_name) FROM table-name
  • 89. FUNCTION … • Consider the following Emp table • SQL query to count employees, satisfying specified condition is, • Result of the above query will be, SELECT COUNT(name) FROM Emp WHERE salary = 8000; eid name age salary 401 Anu 22 9000 402 Shane 29 8000 403 Rohan 34 6000 404 Scott 44 10000 405 Tiger 35 8000 count(name) 2
  • 90. FUNCTION … • COUNT(DISTINCT expression) evaluates expression for each row in a group, and returns the number of unique, non-null values. • Example of COUNT(distinct) : Consider the following Emp table. • SQL query is, • Result of the above query will be, SELECT COUNT(DISTINCT salary) FROM emp; eid name age salary 401 Anu 22 9000 402 Shane 29 8000 403 Rohan 34 6000 404 Scott 44 10000 405 Tiger 35 8000 count(distinct salary) 4
  • 91. FUNCTION • SUM function returns total sum of a selected columns numeric values. • Syntax for SUM is, SELECT SUM(column_name) from table-name;
  • 92. FUNCTION … • Consider the following Emp table • SQL query to find sum of salaries will be, • Result of the above query will be, SELECT SUM(salary) FROM emp; eid name age salary 401 Anu 22 9000 402 Shane 29 8000 403 Rohan 34 6000 404 Scott 44 10000 405 Tiger 35 8000 SUM(salary) 41000
  • 93. FUNCTION • Average returns average value after calculating it from values in a numeric column. • Its general syntax is, SELECT AVG(column_name) FROM table_name
  • 94. FUNCTION … • Consider the following Emp table • SQL query to find average salary will be, • Result of the above query will be, SELECT avg(salary) from Emp; avg(salary) 8200 eid name age salary 401 Anu 22 9000 402 Shane 29 8000 403 Rohan 34 6000 404 Scott 44 10000 405 Tiger 35 8000
  • 95. FUNCTION • MAX function returns maximum value from selected column of the table. • Syntax of MAX function is, SELECT MAX(column_name) from table-name;
  • 96. FUNCTION … • Using MAX() function :Consider the following Emp table • SQL query to find the Maximum salary will be, • Result of the above query will be, SELECT MAX(salary) FROM emp; eid name age salary 401 Anu 22 9000 402 Shane 29 8000 403 Rohan 34 6000 404 Scott 44 10000 405 Tiger 35 8000 MAX(salary) 10000
  • 97. FUNCTION • MIN function returns minimum value from a selected column of the table. • Syntax for MIN function is, SELECT MIN(column_name) from table-name;
  • 98. FUNCTION … • Using MIN() function :Consider the following Emp table • SQL query to find the Minimum salary will be, • Result of the above query will be, SELECT MIN(salary) FROM emp; eid name age salary 401 Anu 22 9000 402 Shane 29 8000 403 Rohan 34 6000 404 Scott 44 10000 405 Tiger 35 8000 MIN(salary) 6000
  • 99. FUNCTION • First function returns first value of a selected column • Syntax for FIRST function is, SELECT FIRST(column_name) from table-name;
  • 100. FUNCTION … • Using FIRST() function :Consider the following Emp table • SQL query will be, • Result of the above query will be, SELECT FIRST(salary) FROM Emp; eid name age salary 401 Anu 22 9000 402 Shane 29 8000 403 Rohan 34 6000 404 Scott 44 10000 405 Tiger 35 8000 first(salary) 9000
  • 101. FUNCTION • LAST function returns the return last value of the selected column. • Syntax of LAST function is, SELECT LAST(column_name) from table-name;
  • 102. FUNCTION … • Using LAST() function :Consider the following Emp table • SQL query will be, • Result of the above query will be, SELECT LAST(salary) FROM Emp; eid name age salary 401 Anu 22 9000 402 Shane 29 8000 403 Rohan 34 6000 404 Scott 44 10000 405 Tiger 35 8000 last(salary) 8000
  • 103. FUNCTION • Scalar functions return a single value from an input value. • Following are some frequently used Scalar Functions in SQL. • UCASE function is used to convert value of string column to Uppercase characters. • Syntax of UCASE, SELECT UCASE(column_name) from table-name;
  • 104. FUNCTION … • Using UCASE() function :Consider the following Emp table • SQL query for using UCASE is, • Result is, SELECT UCASE(name) FROM emp; eid name age salary 401 Anu 22 9000 402 Shane 29 8000 403 Rohan 34 6000 404 Scott 44 10000 405 Tiger 35 8000 UCASE(name) ANU SHANE ROHAN SCOTT TIGER
  • 105. FUNCTION • LCASE function is used to convert value of string columns to Lowecase characters. • Syntax for LCASE is, SELECT LCASE(column_name) from table-name;
  • 106. FUNCTION … • Using LCASE() function :Consider the following Emp table • SQL query for using LCASE is, • Result is, SELECT LCASE(name) FROM emp; eid name age salary 401 Anu 22 9000 402 Shane 29 8000 403 Rohan 34 6000 404 Scott 44 10000 405 Tiger 35 8000 LCASE(name) anu shane rohan scott tiger
  • 107. FUNCTION • MID function is used to extract substrings from column values of string type in a table. • Syntax for MID function is, SELECT MID(column_name, start, length) from table-name;
  • 108. FUNCTION … • Using MID() function :Consider the following Emp table • SQL query will be, • Result is, SELECT MID(name,2,2) FROM emp; eid name age salary 401 Anu 22 9000 402 Shane 29 8000 403 Rohan 34 6000 404 Scott 44 10000 405 Tiger 35 8000 MID(name,2,2) nu ha oh co ig
  • 109. FUNCTION • ROUND function is used to round a numeric field to number of nearest integer. • It is used on Decimal point values. • Syntax of Round function is, SELECT ROUND(column_name, decimals) from table-name;
  • 110. FUNCTION … • Using ROUND() function :Consider the following Emp table • SQL query will be, • Result is, SELECT ROUND(salary) from emp; eid name age salary 401 Anu 22 9000 402 Shane 29 8000 403 Rohan 34 6000 404 Scott 44 10000 405 Tiger 35 8000 ROUND(salary) 9001 8001 6000 10000 8000
  • 111. 9.0 SQL ORDER BY Clause • Order by clause is used with SELECT statement for arranging retrieved data in sorted order. • The Order by clause by default sorts the retrieved data in ascending order. • To sort the data in descending order DESC keyword is used with Order by clause. • Syntax of Order By SELECT column-list|* FROM table-name ORDER BY ASC | DESC;
  • 112. 9.1 SQL ORDER BY Clause … • Using default Order by : Consider the following Emp table, • The above query will return the resultant data in ascending order of the salary. SELECT * FROM Emp ORDER BY salary; eid name age salary 401 Anu 22 9000 402 Shane 29 8000 403 Rohan 34 6000 404 Scott 44 10000 405 Tiger 35 8000 eid name age salary 403 Rohan 34 6000 402 Shane 29 8000 405 Tiger 35 8000 401 Anu 22 9000 404 Scott 44 10000
  • 113. 9.2 SQL ORDER BY Clause … • Using Order by DESC: Consider the following Emp table, • The above query will return the resultant data in descending order of the salary. SELECT * FROM Emp ORDER BY salary DESC; eid name age salary 401 Anu 22 9000 402 Shane 29 8000 403 Rohan 34 6000 404 Scott 44 10000 405 Tiger 35 8000 eid name age salary 404 Scott 44 10000 401 Anu 22 9000 405 Tiger 35 8000 402 Shane 29 8000 403 Rohan 34 6000
  • 114. 10.0 SQL GROUP BY Clause • Group by clause is used to group the results of a SELECT query based on one or more columns. • It is also used with SQL functions to group the result from one or more tables. • Syntax for using Group by in a statement. SELECT column_name, function(column_name) FROM table_name WHERE condition GROUP BY column_name
  • 115. 10.0 SQL GROUP BY Clause … • Example of Group by in a Statement: Consider the following Emp table, • Here we want to find name and age of employees grouped by their salaries or in other words, we will be grouping employees based on their salaries, hence, as a result, we will get a data set, with unique salaries listed, along side the first employee's name and age to have that salary. • group by is used to group different row of data together based on any one column. eid name age salary 401 Anu 22 9000 402 Shane 29 8000 403 Rohan 34 6000 404 Scott 44 10000 405 Tiger 35 8000
  • 116. 10.0 SQL GROUP BY Clause … • SQL query for the above requirement will be, • Result will be, SELECT name, age FROM Emp GROUP BY salary name age Rohan 34 Shane 29 Anu 22
  • 117. 10.0 SQL GROUP BY Clause … • Example of Group by in a Statement with WHERE clause: Consider the following Emp table, • SQL query will be, group by is used to group different row of data together based on any one column. • Result will be, eid name age salary 401 Anu 22 9000 402 Shane 29 8000 403 Rohan 34 6000 404 Scott 44 10000 405 Tiger 35 8000 SELECT name, salary FROM Emp WHERE age > 25 GROUP BY salary name salary Rohan 6000 Shane 8000 Scott 9000
  • 118. 3.3 DCL Commands • DCL is short name of Data Control Language which includes commands such as GRANT and mostly concerned with rights, permissions and other controls of the database system.  GRANT - allow users access privileges to the database  REVOKE - withdraw users access privileges given by using the GRANT command
  • 119. 3.4 TCL Commands • TCL is short name of Transaction Control Language which deals with a transaction within a database.  COMMIT - commits a Transaction  ROLLBACK - rollback a transaction in case of any error occurs  SAVEPOINT - to rollback the transaction making points within groups  SET TRANSACTION - specify characteristics of the transaction