SlideShare a Scribd company logo
Database Lab 2
Swapnali Pawar
Swapnali Pawar
The SQL CREATE DATABASE Statement
The CREATE DATABASE statement is used to create
a new SQL database.
Syntax
CREATE DATABASE databasename;
Make sure you have admin privilege before creating any
database. Once a database is created, you can check it in the
list of databases with the following SQL command:
SHOW DATABASES;
DATABASE
Swapnali Pawar
The SQL DROP DATABASE
Statement
The DROP DATABASE statement is used to
drop an existing SQL database.
Syntax
DROP DATABASE databasename;
Note: Be careful before dropping a database. Deleting a
database will result in loss of complete information stored in
the database!
Swapnali Pawar
A. Tables
1.Basic Data Types-
char,varchar,varchar2,long,number,fixed
2.Commands to Create Table-
create table
3.Commands to Handle Tables-
Alter
Drop
Insert
Swapnali Pawar
1.Basic Data Types-
• Each column in a database table is required to have a
name and a data type.
• An SQL developer must decide what type of data that
will be stored inside each column when creating a table.
• The data type is a guideline for SQL to understand what
type of data is expected inside of each column, and it
also identifies how SQL will interact with the stored
data.
Note: Data types might have different names in different
database. And even if the name is the same, the size and
other details may be different! Always check the
documentation!
Swapnali Pawar
In MySQL there are three main data types:
1.String 2.numeric 3.date and time.
1.String Datatype
Swapnali Pawar
2. Numeric Datatypes
Swapnali Pawar
3. date and time
Swapnali Pawar
2.Commands to Create Table-
The CREATE TABLE statement is used to create a new table in a
database.
Syntax
CREATE TABLE table_name (
column1 datatype,
column2 datatype,
column3 datatype,
....
);
Example-
CREATE TABLE Persons (
PersonID int,
LastName varchar(255),
FirstName varchar(255),
Address varchar(255),
City varchar(255)
); Swapnali Pawar
3.Commands to Handle Tables
Alter , Drop , Insert
Example
ALTER TABLE Customers
ADD Email varchar(255);
Swapnali Pawar
The SQL DROP TABLE Statement
The DROP TABLE statement is used to drop an
existing table in a database.
Syntax
DROP TABLE table_name;
Note: Be careful before dropping a table. Deleting a table will
result in loss of complete information stored in the table!
Example
DROP TABLE myfriends;
Swapnali Pawar
The SQL INSERT INTO Statement
The INSERT INTO statement is used to insert new records in a table.
It is possible to write the INSERT INTO statement in two ways:
1. Specify both the column names and the values to be inserted:
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);
2. If you are adding values for all the columns of the table, you do not need to
specify the column names in the SQL query. However, make sure the order of
the values is in the same order as the columns in the table. Here, the INSERT
INTO syntax would be as follows:
INSERT INTO table_name
VALUES (value1, value2, value3, ...);
Swapnali Pawar
B. Commands for Record Handling
1. Update,Select,Delete
2. With arithmetic,comparision,logical operators
• And
• OR
• Between
• In
• Like
3. Order by
4. Group by
Swapnali Pawar
1. Update,Select,Delete
UPDATE Syntax
The UPDATE statement is used to modify the existing records in a table.
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
DELETE Syntax
The DELETE statement is used to delete existing records in a table.
DELETE FROM table_name WHERE condition;
Be careful when deleting records in a table! Notice the WHERE clause in the DELETE statement.
The WHERE clause specifies which record(s) should be deleted. If you omit the WHERE clause, all
records in the table will be deleted!
SELECT Syntax
The SELECT statement is used to select data from a database.
The data returned is stored in a result table, called the result-set.
SELECT column1, column2, ...
FROM table_name;
Here, column1, column2, ... are the field names of the table you want to select data
from. If you want to select all the fields available in the table, use the following
syntax:
SELECT * FROM table_name;
Swapnali Pawar
2. With arithmetic,comparision,logical operators
(And,OR,Between,In,Like)
AND Syntax- The AND operator displays a record if all the conditions
separated by AND are TRUE.
SELECT column1, column2, ...
FROM table_name
WHERE condition1 AND condition2 AND condition3 ...;
OR Syntax- The OR operator displays a record if any of the conditions separated
by OR is TRUE.
SELECT column1, column2, ...
FROM table_name
WHERE condition1 OR condition2 OR condition3 ...;
NOT Syntax- The NOT operator displays a record if the condition(s) is NOT TRUE.
SELECT column1, column2, ...
FROM table_name
WHERE NOT condition;
Swapnali Pawar
BETWEEN
The BETWEEN command is used to select values within a given range. The values can be numbers, text,
or dates.
The BETWEEN command is inclusive: begin and end values are included.
The following SQL statement selects all products with a price BETWEEN 10 and 20:
Example
SELECT * FROM Products
WHERE Price BETWEEN 10 AND 20;
SELECT * FROM Products
WHERE Price NOT BETWEEN 10 AND 20;
IN Operator
The IN operator allows you to specify multiple values in a WHERE clause.
The IN operator is a shorthand for multiple OR conditions.
SELECT column_name(s)
FROM table_name
WHERE column_name IN (value1, value2, ...);
Example
SELECT * FROM Customers
WHERE Country IN ('Germany', 'France', 'UK');
Swapnali Pawar
The SQL LIKE Operator
The LIKE operator is used in a WHERE clause to search for a specified pattern in a
column.
There are two wildcards often used in conjunction with the LIKE operator:
• The percent sign (%) represents zero, one, or multiple characters
• The underscore sign (_) represents one, single character
Note: MS Access uses an asterisk (*) instead of the percent sign (%), and a
question mark (?) instead of the underscore (_).
LIKE Syntax
SELECT column1, column2, ...
FROM table_name
WHERE columnN LIKE pattern;
SQL LIKE Examples
The following SQL statement selects all customers with a CustomerName starting
with "a":
Example
SELECT * FROM Customers
WHERE CustomerName LIKE 'a%'; Swapnali Pawar
LIKE Operator Description
WHERE CustomerName LIKE 'a%' Finds any values that start with "a"
WHERE CustomerName LIKE '%a' Finds any values that end with "a"
WHERE CustomerName LIKE '%or%' Finds any values that have "or" in any
position
WHERE CustomerName LIKE '_r%' Finds any values that have "r" in the second
position
WHERE CustomerName LIKE 'a_%' Finds any values that start with "a" and are
at least 2 characters in length
WHERE CustomerName LIKE 'a__%' Finds any values that start with "a" and are
at least 3 characters in length
WHERE ContactName LIKE 'a%o' Finds any values that start with "a" and ends
with "o"
Here are some examples showing different LIKE operators with '%' and '_' wildcards:
Swapnali Pawar
3. The SQL ORDER BY Keyword
The ORDER BY keyword is used to sort the result-set in ascending or
descending order.
The ORDER BY keyword sorts the records in ascending order by default.
To sort the records in descending order, use the DESC keyword.
ORDER BY Syntax
SELECT column1, column2, ...
FROM table_name
ORDER BY column1, column2, ... ASC|DESC;
Example
SELECT * FROM Customers
ORDER BY Country DESC;
Swapnali Pawar
4. The SQL GROUP BY Statement
The GROUP BY statement groups rows that have the same values into
summary rows, like "find the number of customers in each country".
The GROUP BY statement is often used with aggregate functions
(COUNT(), MAX(), MIN(), SUM(), AVG()) to group the result-set by one or
more columns.
GROUP BY Syntax
SELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY column_name(s)
ORDER BY column_name(s);
Example
SELECT COUNT(CustomerID), Country
FROM Customers
GROUP BY Country
Swapnali Pawar
C. SQL Functions
1. Date
2. Numeric
3. Character conversion
4. Group Functions
Avg , Max , Min , Sum , Count
5. Set Operations-
Union , Union all, intersect, minus
Swapnali Pawar
1. Date
Swapnali Pawar
Date Operations :
SELECT CURTIME();
SELECT CURDATE()
SELECT DATE_ADD('1994-16-12',INTERVAL 31 DAY);
SELECT DAYNAME('1994-12-16');
SELECT DAYOFMONTH('1994-12-16');
SELECT DAYOFWEEK('1995-12-16');
SELECT DAYOFYEAR('1995-12-16');
SELECT FROM_DAYS(729669);
Swapnali Pawar
2. Numeric
Swapnali Pawar
ABS(X)
The ABS() function returns the absolute value of X. Consider the following
example −
SQL> SELECT ABS(2);
2. Numeric Functions
CEILING(X)
These functions return the smallest integer value that is not smaller than X. Consider the
following example −
SQL> SELECT CEILING(3.46);
CEILING(3.46)
4
COS(X)
This function returns the cosine of X. The value of X is given in radians.
SQL>SELECT COS(90);
COS(90)
-0.44807361612917
FLOOR(X)
This function returns the largest integer value that is not greater than X.
SQL>SELECT FLOOR(7.55);
FLOOR(7.55)
7 Swapnali Pawar
3. Character conversion
Swapnali Pawar
• SELECT CONCAT(first_name, ' ',last_name) as full_name from myfriends;
• SELECT length(first_name) as full_name from myfriends;
• SELECT length(concat(first_name,last_name)) as full_name from myfriends;
• SELECT lower(first_name) as full_name from myfriends;
• SELECT ucase(first_name) as full_name from myfriends;
• SELECT upper(first_name) as full_name from myfriends;
• SELECT ltrim(first_name) as full_name from myfriends;
• SELECT mid(first_name,1,2) as full_name from myfriends;
• SELECT reverse(first_name) as full_name from myfriends;
String Operation
Swapnali Pawar
4. Group Functions
Avg , Max , Min , Sum , Count
COUNT() Syntax-
The COUNT() function returns the number of rows that matches a
specified criterion.
SELECT COUNT(column_name)
FROM table_name
WHERE condition;
AVG() Syntax-
The AVG() function returns the average value of a numeric
column
SELECT AVG(column_name)
FROM table_name
WHERE condition;
SUM() Syntax
The SUM() function returns the total sum of a numeric column.
SELECT SUM(column_name)
FROM table_name
WHERE condition;
Swapnali Pawar
The SQL MIN() and MAX() Function
MIN() Syntax
SELECT MIN(column_name)
FROM table_name
WHERE condition;
MAX() Syntax
SELECT MAX(column_name)
FROM table_name
WHERE condition;
The MAX() function returns the largest value of the selected
column
The MIN() function returns the smallest value of the selected
column.
Swapnali Pawar
5. Set Operations-
Union , Union all, intersect, minus
UNION
The UNION command combines the result set of two or more
SELECT statements (only distinct values). it will eliminate duplicate
rows from its resultset.
The following SQL statement returns the cities (only distinct values)
from both the "Customers" and the "Suppliers" table:
Example
SELECT City FROM Customers
UNION
SELECT City FROM Suppliers
ORDER BY City;
Swapnali Pawar
UNION Example
Swapnali Pawar
UNION ALL
The UNION ALL command combines the result set of two
or more SELECT statements (allows duplicate values).
The following SQL statement returns the cities
(duplicate values also) from both the "Customers" and
the "Suppliers" table:
Example
SELECT City FROM Customers
UNION ALL
SELECT City FROM Suppliers
ORDER BY City;
Swapnali Pawar
UNION ALL Example
Swapnali Pawar
Intersect
Intersect operation is used to combine two SELECT statements,
but it only retuns the records which are common from
both SELECT statements. In case of Intersect the number of
columns and datatype must be same.
SELECT * FROM First
INTERSECT
SELECT * FROM Second;
Swapnali Pawar
Intersect Example
Swapnali Pawar
MINUS
The Minus operation combines results of two SELECT statements
and return only those in the final result, which belongs to the first
set of the result
SELECT * FROM First
MINUS
SELECT * FROM Second;
Swapnali Pawar
MINUS Operation Example
Swapnali Pawar
Student Activity
• Create table myfriends & execute
all queries on that table
CREATE TABLE myfriends
(
last_name VARCHAR(15) NOT NULL,
first_name VARCHAR(15) NOT NULL,
suffix VARCHAR(5) NULL,
sex VARCHAR(1) NULL,
city VARCHAR(20) NOT NULL,
state VARCHAR(2) NOT NULL,
age int
);
Swapnali Pawar
Swapnali Pawar

More Related Content

What's hot

Advanced SQL Webinar
Advanced SQL WebinarAdvanced SQL Webinar
Advanced SQL Webinar
Ram Kedem
 
Nested Queries Lecture
Nested Queries LectureNested Queries Lecture
Nested Queries Lecture
Felipe Costa
 
SQL Tutorial for Beginners
SQL Tutorial for BeginnersSQL Tutorial for Beginners
SQL Tutorial for Beginners
Abdelhay Shafi
 
Database Systems - SQL - DDL Statements (Chapter 3/2)
Database Systems - SQL - DDL Statements (Chapter 3/2)Database Systems - SQL - DDL Statements (Chapter 3/2)
Database Systems - SQL - DDL Statements (Chapter 3/2)
Vidyasagar Mundroy
 
SQL report
SQL reportSQL report
SQL report
Ahmad Zahid
 
SQL Overview
SQL OverviewSQL Overview
SQL Overview
Stewart Rogers
 
SQL Server Learning Drive
SQL Server Learning Drive SQL Server Learning Drive
SQL Server Learning Drive
TechandMate
 
MY SQL
MY SQLMY SQL
MY SQL
sundar
 
Oracle Sql & PLSQL Complete guide
Oracle Sql & PLSQL Complete guideOracle Sql & PLSQL Complete guide
Oracle Sql & PLSQL Complete guide
Raviteja Chowdary Adusumalli
 
SQL Tutorial - Basic Commands
SQL Tutorial - Basic CommandsSQL Tutorial - Basic Commands
SQL Tutorial - Basic Commands
1keydata
 
SQL Fundamentals
SQL FundamentalsSQL Fundamentals
SQL Fundamentals
Brian Foote
 
Database Systems - SQL - DDL Statements (Chapter 3/3)
Database Systems - SQL - DDL Statements (Chapter 3/3)Database Systems - SQL - DDL Statements (Chapter 3/3)
Database Systems - SQL - DDL Statements (Chapter 3/3)
Vidyasagar Mundroy
 
SQL select statement and functions
SQL select statement and functionsSQL select statement and functions
SQL select statement and functionsVikas Gupta
 
Null values, insert, delete and update in database
Null values, insert, delete and update in databaseNull values, insert, delete and update in database
Null values, insert, delete and update in database
Hemant Suthar
 
A must Sql notes for beginners
A must Sql notes for beginnersA must Sql notes for beginners
A must Sql notes for beginners
Ram Sagar Mourya
 
SQL Tunning
SQL TunningSQL Tunning
SQL Tunning
Dhananjay Goel
 

What's hot (18)

Advanced SQL Webinar
Advanced SQL WebinarAdvanced SQL Webinar
Advanced SQL Webinar
 
Mysql cheatsheet
Mysql cheatsheetMysql cheatsheet
Mysql cheatsheet
 
Nested Queries Lecture
Nested Queries LectureNested Queries Lecture
Nested Queries Lecture
 
Query
QueryQuery
Query
 
SQL Tutorial for Beginners
SQL Tutorial for BeginnersSQL Tutorial for Beginners
SQL Tutorial for Beginners
 
Database Systems - SQL - DDL Statements (Chapter 3/2)
Database Systems - SQL - DDL Statements (Chapter 3/2)Database Systems - SQL - DDL Statements (Chapter 3/2)
Database Systems - SQL - DDL Statements (Chapter 3/2)
 
SQL report
SQL reportSQL report
SQL report
 
SQL Overview
SQL OverviewSQL Overview
SQL Overview
 
SQL Server Learning Drive
SQL Server Learning Drive SQL Server Learning Drive
SQL Server Learning Drive
 
MY SQL
MY SQLMY SQL
MY SQL
 
Oracle Sql & PLSQL Complete guide
Oracle Sql & PLSQL Complete guideOracle Sql & PLSQL Complete guide
Oracle Sql & PLSQL Complete guide
 
SQL Tutorial - Basic Commands
SQL Tutorial - Basic CommandsSQL Tutorial - Basic Commands
SQL Tutorial - Basic Commands
 
SQL Fundamentals
SQL FundamentalsSQL Fundamentals
SQL Fundamentals
 
Database Systems - SQL - DDL Statements (Chapter 3/3)
Database Systems - SQL - DDL Statements (Chapter 3/3)Database Systems - SQL - DDL Statements (Chapter 3/3)
Database Systems - SQL - DDL Statements (Chapter 3/3)
 
SQL select statement and functions
SQL select statement and functionsSQL select statement and functions
SQL select statement and functions
 
Null values, insert, delete and update in database
Null values, insert, delete and update in databaseNull values, insert, delete and update in database
Null values, insert, delete and update in database
 
A must Sql notes for beginners
A must Sql notes for beginnersA must Sql notes for beginners
A must Sql notes for beginners
 
SQL Tunning
SQL TunningSQL Tunning
SQL Tunning
 

Similar to Database Management System 1

Sql
SqlSql
Oraclesql
OraclesqlOraclesql
Oraclesql
Priya Goyal
 
Mysql 120831075600-phpapp01
Mysql 120831075600-phpapp01Mysql 120831075600-phpapp01
Mysql 120831075600-phpapp01sagaroceanic11
 
My SQL.pptx
My SQL.pptxMy SQL.pptx
My SQL.pptx
KieveBarreto1
 
Creating database using sql commands
Creating database using sql commandsCreating database using sql commands
Creating database using sql commandsBelle Wx
 
SQL Query
SQL QuerySQL Query
SQL Query
Imam340267
 
Select To Order By
Select  To  Order BySelect  To  Order By
Select To Order By
Krizia Capacio
 
Database development coding standards
Database development coding standardsDatabase development coding standards
Database development coding standardsAlessandro Baratella
 
Oracle basic queries
Oracle basic queriesOracle basic queries
Oracle basic queries
PRAKHAR JHA
 
SQL PPT.pptx
SQL PPT.pptxSQL PPT.pptx
SQL PPT.pptx
PriyaPandey767008
 
1670595076250.pdf
1670595076250.pdf1670595076250.pdf
1670595076250.pdf
GaneshR321894
 
Cheat sheet SQL commands with examples and easy understanding
Cheat sheet SQL commands with examples and easy understandingCheat sheet SQL commands with examples and easy understanding
Cheat sheet SQL commands with examples and easy understanding
VivekanandaGN1
 
SQL 🌟🌟🔥.pdf
SQL 🌟🌟🔥.pdfSQL 🌟🌟🔥.pdf
SQL 🌟🌟🔥.pdf
LightWolf2
 
SQL learning notes and all code.pdf
SQL learning notes and all code.pdfSQL learning notes and all code.pdf
SQL learning notes and all code.pdf
79TarannumMulla
 
SQL | DML
SQL | DMLSQL | DML
SQL | DML
To Sum It Up
 
SQL Beginners anishurrehman.cloud.pdf
SQL Beginners anishurrehman.cloud.pdfSQL Beginners anishurrehman.cloud.pdf
SQL Beginners anishurrehman.cloud.pdf
AnishurRehman1
 
DBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptxDBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptx
jainendraKUMAR55
 
SQL
SQLSQL

Similar to Database Management System 1 (20)

Sql
SqlSql
Sql
 
Oraclesql
OraclesqlOraclesql
Oraclesql
 
Sql
SqlSql
Sql
 
Mysql 120831075600-phpapp01
Mysql 120831075600-phpapp01Mysql 120831075600-phpapp01
Mysql 120831075600-phpapp01
 
My SQL.pptx
My SQL.pptxMy SQL.pptx
My SQL.pptx
 
Creating database using sql commands
Creating database using sql commandsCreating database using sql commands
Creating database using sql commands
 
SQL Query
SQL QuerySQL Query
SQL Query
 
Hira
HiraHira
Hira
 
Select To Order By
Select  To  Order BySelect  To  Order By
Select To Order By
 
Database development coding standards
Database development coding standardsDatabase development coding standards
Database development coding standards
 
Oracle basic queries
Oracle basic queriesOracle basic queries
Oracle basic queries
 
SQL PPT.pptx
SQL PPT.pptxSQL PPT.pptx
SQL PPT.pptx
 
1670595076250.pdf
1670595076250.pdf1670595076250.pdf
1670595076250.pdf
 
Cheat sheet SQL commands with examples and easy understanding
Cheat sheet SQL commands with examples and easy understandingCheat sheet SQL commands with examples and easy understanding
Cheat sheet SQL commands with examples and easy understanding
 
SQL 🌟🌟🔥.pdf
SQL 🌟🌟🔥.pdfSQL 🌟🌟🔥.pdf
SQL 🌟🌟🔥.pdf
 
SQL learning notes and all code.pdf
SQL learning notes and all code.pdfSQL learning notes and all code.pdf
SQL learning notes and all code.pdf
 
SQL | DML
SQL | DMLSQL | DML
SQL | DML
 
SQL Beginners anishurrehman.cloud.pdf
SQL Beginners anishurrehman.cloud.pdfSQL Beginners anishurrehman.cloud.pdf
SQL Beginners anishurrehman.cloud.pdf
 
DBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptxDBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptx
 
SQL
SQLSQL
SQL
 

More from Swapnali Pawar

Unit 3 introduction to android
Unit 3 introduction to android Unit 3 introduction to android
Unit 3 introduction to android
Swapnali Pawar
 
Unit 1-Introduction to Mobile Computing
Unit 1-Introduction to Mobile ComputingUnit 1-Introduction to Mobile Computing
Unit 1-Introduction to Mobile Computing
Swapnali Pawar
 
Unit 2.design mobile computing architecture
Unit 2.design mobile computing architectureUnit 2.design mobile computing architecture
Unit 2.design mobile computing architecture
Swapnali Pawar
 
Introduction to ios
Introduction to iosIntroduction to ios
Introduction to ios
Swapnali Pawar
 
Fresher interview tips demo
Fresher interview tips demoFresher interview tips demo
Fresher interview tips demo
Swapnali Pawar
 
Introduction to android
Introduction to androidIntroduction to android
Introduction to android
Swapnali Pawar
 
Android Introduction
Android IntroductionAndroid Introduction
Android Introduction
Swapnali Pawar
 
Unit 2.design computing architecture 2.1
Unit 2.design computing architecture 2.1Unit 2.design computing architecture 2.1
Unit 2.design computing architecture 2.1
Swapnali Pawar
 
Unit 2 Design mobile computing architecture MC1514
Unit 2 Design mobile computing architecture MC1514Unit 2 Design mobile computing architecture MC1514
Unit 2 Design mobile computing architecture MC1514
Swapnali Pawar
 
Design computing architecture ~ Mobile Technologies
Design computing architecture ~ Mobile TechnologiesDesign computing architecture ~ Mobile Technologies
Design computing architecture ~ Mobile Technologies
Swapnali Pawar
 
Exception Handling
Exception Handling Exception Handling
Exception Handling
Swapnali Pawar
 
Mobile technology-Unit 1
Mobile technology-Unit 1Mobile technology-Unit 1
Mobile technology-Unit 1
Swapnali Pawar
 
Mobile Technology 3
Mobile Technology 3Mobile Technology 3
Mobile Technology 3
Swapnali Pawar
 
Web Programming& Scripting Lab
Web Programming& Scripting LabWeb Programming& Scripting Lab
Web Programming& Scripting Lab
Swapnali Pawar
 
Mobile Technology
Mobile TechnologyMobile Technology
Mobile Technology
Swapnali Pawar
 
Mobile Technology
Mobile TechnologyMobile Technology
Mobile Technology
Swapnali Pawar
 
web programming & scripting 2
web programming & scripting 2web programming & scripting 2
web programming & scripting 2
Swapnali Pawar
 
web programming & scripting
web programming & scriptingweb programming & scripting
web programming & scripting
Swapnali Pawar
 

More from Swapnali Pawar (18)

Unit 3 introduction to android
Unit 3 introduction to android Unit 3 introduction to android
Unit 3 introduction to android
 
Unit 1-Introduction to Mobile Computing
Unit 1-Introduction to Mobile ComputingUnit 1-Introduction to Mobile Computing
Unit 1-Introduction to Mobile Computing
 
Unit 2.design mobile computing architecture
Unit 2.design mobile computing architectureUnit 2.design mobile computing architecture
Unit 2.design mobile computing architecture
 
Introduction to ios
Introduction to iosIntroduction to ios
Introduction to ios
 
Fresher interview tips demo
Fresher interview tips demoFresher interview tips demo
Fresher interview tips demo
 
Introduction to android
Introduction to androidIntroduction to android
Introduction to android
 
Android Introduction
Android IntroductionAndroid Introduction
Android Introduction
 
Unit 2.design computing architecture 2.1
Unit 2.design computing architecture 2.1Unit 2.design computing architecture 2.1
Unit 2.design computing architecture 2.1
 
Unit 2 Design mobile computing architecture MC1514
Unit 2 Design mobile computing architecture MC1514Unit 2 Design mobile computing architecture MC1514
Unit 2 Design mobile computing architecture MC1514
 
Design computing architecture ~ Mobile Technologies
Design computing architecture ~ Mobile TechnologiesDesign computing architecture ~ Mobile Technologies
Design computing architecture ~ Mobile Technologies
 
Exception Handling
Exception Handling Exception Handling
Exception Handling
 
Mobile technology-Unit 1
Mobile technology-Unit 1Mobile technology-Unit 1
Mobile technology-Unit 1
 
Mobile Technology 3
Mobile Technology 3Mobile Technology 3
Mobile Technology 3
 
Web Programming& Scripting Lab
Web Programming& Scripting LabWeb Programming& Scripting Lab
Web Programming& Scripting Lab
 
Mobile Technology
Mobile TechnologyMobile Technology
Mobile Technology
 
Mobile Technology
Mobile TechnologyMobile Technology
Mobile Technology
 
web programming & scripting 2
web programming & scripting 2web programming & scripting 2
web programming & scripting 2
 
web programming & scripting
web programming & scriptingweb programming & scripting
web programming & scripting
 

Recently uploaded

The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 

Recently uploaded (20)

The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 

Database Management System 1

  • 1. Database Lab 2 Swapnali Pawar Swapnali Pawar
  • 2. The SQL CREATE DATABASE Statement The CREATE DATABASE statement is used to create a new SQL database. Syntax CREATE DATABASE databasename; Make sure you have admin privilege before creating any database. Once a database is created, you can check it in the list of databases with the following SQL command: SHOW DATABASES; DATABASE Swapnali Pawar
  • 3. The SQL DROP DATABASE Statement The DROP DATABASE statement is used to drop an existing SQL database. Syntax DROP DATABASE databasename; Note: Be careful before dropping a database. Deleting a database will result in loss of complete information stored in the database! Swapnali Pawar
  • 4. A. Tables 1.Basic Data Types- char,varchar,varchar2,long,number,fixed 2.Commands to Create Table- create table 3.Commands to Handle Tables- Alter Drop Insert Swapnali Pawar
  • 5. 1.Basic Data Types- • Each column in a database table is required to have a name and a data type. • An SQL developer must decide what type of data that will be stored inside each column when creating a table. • The data type is a guideline for SQL to understand what type of data is expected inside of each column, and it also identifies how SQL will interact with the stored data. Note: Data types might have different names in different database. And even if the name is the same, the size and other details may be different! Always check the documentation! Swapnali Pawar
  • 6. In MySQL there are three main data types: 1.String 2.numeric 3.date and time. 1.String Datatype Swapnali Pawar
  • 8. 3. date and time Swapnali Pawar
  • 9. 2.Commands to Create Table- The CREATE TABLE statement is used to create a new table in a database. Syntax CREATE TABLE table_name ( column1 datatype, column2 datatype, column3 datatype, .... ); Example- CREATE TABLE Persons ( PersonID int, LastName varchar(255), FirstName varchar(255), Address varchar(255), City varchar(255) ); Swapnali Pawar
  • 10. 3.Commands to Handle Tables Alter , Drop , Insert Example ALTER TABLE Customers ADD Email varchar(255); Swapnali Pawar
  • 11. The SQL DROP TABLE Statement The DROP TABLE statement is used to drop an existing table in a database. Syntax DROP TABLE table_name; Note: Be careful before dropping a table. Deleting a table will result in loss of complete information stored in the table! Example DROP TABLE myfriends; Swapnali Pawar
  • 12. The SQL INSERT INTO Statement The INSERT INTO statement is used to insert new records in a table. It is possible to write the INSERT INTO statement in two ways: 1. Specify both the column names and the values to be inserted: INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1, value2, value3, ...); 2. If you are adding values for all the columns of the table, you do not need to specify the column names in the SQL query. However, make sure the order of the values is in the same order as the columns in the table. Here, the INSERT INTO syntax would be as follows: INSERT INTO table_name VALUES (value1, value2, value3, ...); Swapnali Pawar
  • 13. B. Commands for Record Handling 1. Update,Select,Delete 2. With arithmetic,comparision,logical operators • And • OR • Between • In • Like 3. Order by 4. Group by Swapnali Pawar
  • 14. 1. Update,Select,Delete UPDATE Syntax The UPDATE statement is used to modify the existing records in a table. UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition; DELETE Syntax The DELETE statement is used to delete existing records in a table. DELETE FROM table_name WHERE condition; Be careful when deleting records in a table! Notice the WHERE clause in the DELETE statement. The WHERE clause specifies which record(s) should be deleted. If you omit the WHERE clause, all records in the table will be deleted! SELECT Syntax The SELECT statement is used to select data from a database. The data returned is stored in a result table, called the result-set. SELECT column1, column2, ... FROM table_name; Here, column1, column2, ... are the field names of the table you want to select data from. If you want to select all the fields available in the table, use the following syntax: SELECT * FROM table_name; Swapnali Pawar
  • 15. 2. With arithmetic,comparision,logical operators (And,OR,Between,In,Like) AND Syntax- The AND operator displays a record if all the conditions separated by AND are TRUE. SELECT column1, column2, ... FROM table_name WHERE condition1 AND condition2 AND condition3 ...; OR Syntax- The OR operator displays a record if any of the conditions separated by OR is TRUE. SELECT column1, column2, ... FROM table_name WHERE condition1 OR condition2 OR condition3 ...; NOT Syntax- The NOT operator displays a record if the condition(s) is NOT TRUE. SELECT column1, column2, ... FROM table_name WHERE NOT condition; Swapnali Pawar
  • 16. BETWEEN The BETWEEN command is used to select values within a given range. The values can be numbers, text, or dates. The BETWEEN command is inclusive: begin and end values are included. The following SQL statement selects all products with a price BETWEEN 10 and 20: Example SELECT * FROM Products WHERE Price BETWEEN 10 AND 20; SELECT * FROM Products WHERE Price NOT BETWEEN 10 AND 20; IN Operator The IN operator allows you to specify multiple values in a WHERE clause. The IN operator is a shorthand for multiple OR conditions. SELECT column_name(s) FROM table_name WHERE column_name IN (value1, value2, ...); Example SELECT * FROM Customers WHERE Country IN ('Germany', 'France', 'UK'); Swapnali Pawar
  • 17. The SQL LIKE Operator The LIKE operator is used in a WHERE clause to search for a specified pattern in a column. There are two wildcards often used in conjunction with the LIKE operator: • The percent sign (%) represents zero, one, or multiple characters • The underscore sign (_) represents one, single character Note: MS Access uses an asterisk (*) instead of the percent sign (%), and a question mark (?) instead of the underscore (_). LIKE Syntax SELECT column1, column2, ... FROM table_name WHERE columnN LIKE pattern; SQL LIKE Examples The following SQL statement selects all customers with a CustomerName starting with "a": Example SELECT * FROM Customers WHERE CustomerName LIKE 'a%'; Swapnali Pawar
  • 18. LIKE Operator Description WHERE CustomerName LIKE 'a%' Finds any values that start with "a" WHERE CustomerName LIKE '%a' Finds any values that end with "a" WHERE CustomerName LIKE '%or%' Finds any values that have "or" in any position WHERE CustomerName LIKE '_r%' Finds any values that have "r" in the second position WHERE CustomerName LIKE 'a_%' Finds any values that start with "a" and are at least 2 characters in length WHERE CustomerName LIKE 'a__%' Finds any values that start with "a" and are at least 3 characters in length WHERE ContactName LIKE 'a%o' Finds any values that start with "a" and ends with "o" Here are some examples showing different LIKE operators with '%' and '_' wildcards: Swapnali Pawar
  • 19. 3. The SQL ORDER BY Keyword The ORDER BY keyword is used to sort the result-set in ascending or descending order. The ORDER BY keyword sorts the records in ascending order by default. To sort the records in descending order, use the DESC keyword. ORDER BY Syntax SELECT column1, column2, ... FROM table_name ORDER BY column1, column2, ... ASC|DESC; Example SELECT * FROM Customers ORDER BY Country DESC; Swapnali Pawar
  • 20. 4. The SQL GROUP BY Statement The GROUP BY statement groups rows that have the same values into summary rows, like "find the number of customers in each country". The GROUP BY statement is often used with aggregate functions (COUNT(), MAX(), MIN(), SUM(), AVG()) to group the result-set by one or more columns. GROUP BY Syntax SELECT column_name(s) FROM table_name WHERE condition GROUP BY column_name(s) ORDER BY column_name(s); Example SELECT COUNT(CustomerID), Country FROM Customers GROUP BY Country Swapnali Pawar
  • 21. C. SQL Functions 1. Date 2. Numeric 3. Character conversion 4. Group Functions Avg , Max , Min , Sum , Count 5. Set Operations- Union , Union all, intersect, minus Swapnali Pawar
  • 23. Date Operations : SELECT CURTIME(); SELECT CURDATE() SELECT DATE_ADD('1994-16-12',INTERVAL 31 DAY); SELECT DAYNAME('1994-12-16'); SELECT DAYOFMONTH('1994-12-16'); SELECT DAYOFWEEK('1995-12-16'); SELECT DAYOFYEAR('1995-12-16'); SELECT FROM_DAYS(729669); Swapnali Pawar
  • 25. ABS(X) The ABS() function returns the absolute value of X. Consider the following example − SQL> SELECT ABS(2); 2. Numeric Functions CEILING(X) These functions return the smallest integer value that is not smaller than X. Consider the following example − SQL> SELECT CEILING(3.46); CEILING(3.46) 4 COS(X) This function returns the cosine of X. The value of X is given in radians. SQL>SELECT COS(90); COS(90) -0.44807361612917 FLOOR(X) This function returns the largest integer value that is not greater than X. SQL>SELECT FLOOR(7.55); FLOOR(7.55) 7 Swapnali Pawar
  • 27. • SELECT CONCAT(first_name, ' ',last_name) as full_name from myfriends; • SELECT length(first_name) as full_name from myfriends; • SELECT length(concat(first_name,last_name)) as full_name from myfriends; • SELECT lower(first_name) as full_name from myfriends; • SELECT ucase(first_name) as full_name from myfriends; • SELECT upper(first_name) as full_name from myfriends; • SELECT ltrim(first_name) as full_name from myfriends; • SELECT mid(first_name,1,2) as full_name from myfriends; • SELECT reverse(first_name) as full_name from myfriends; String Operation Swapnali Pawar
  • 28. 4. Group Functions Avg , Max , Min , Sum , Count COUNT() Syntax- The COUNT() function returns the number of rows that matches a specified criterion. SELECT COUNT(column_name) FROM table_name WHERE condition; AVG() Syntax- The AVG() function returns the average value of a numeric column SELECT AVG(column_name) FROM table_name WHERE condition; SUM() Syntax The SUM() function returns the total sum of a numeric column. SELECT SUM(column_name) FROM table_name WHERE condition; Swapnali Pawar
  • 29. The SQL MIN() and MAX() Function MIN() Syntax SELECT MIN(column_name) FROM table_name WHERE condition; MAX() Syntax SELECT MAX(column_name) FROM table_name WHERE condition; The MAX() function returns the largest value of the selected column The MIN() function returns the smallest value of the selected column. Swapnali Pawar
  • 30. 5. Set Operations- Union , Union all, intersect, minus UNION The UNION command combines the result set of two or more SELECT statements (only distinct values). it will eliminate duplicate rows from its resultset. The following SQL statement returns the cities (only distinct values) from both the "Customers" and the "Suppliers" table: Example SELECT City FROM Customers UNION SELECT City FROM Suppliers ORDER BY City; Swapnali Pawar
  • 32. UNION ALL The UNION ALL command combines the result set of two or more SELECT statements (allows duplicate values). The following SQL statement returns the cities (duplicate values also) from both the "Customers" and the "Suppliers" table: Example SELECT City FROM Customers UNION ALL SELECT City FROM Suppliers ORDER BY City; Swapnali Pawar
  • 34. Intersect Intersect operation is used to combine two SELECT statements, but it only retuns the records which are common from both SELECT statements. In case of Intersect the number of columns and datatype must be same. SELECT * FROM First INTERSECT SELECT * FROM Second; Swapnali Pawar
  • 36. MINUS The Minus operation combines results of two SELECT statements and return only those in the final result, which belongs to the first set of the result SELECT * FROM First MINUS SELECT * FROM Second; Swapnali Pawar
  • 38. Student Activity • Create table myfriends & execute all queries on that table CREATE TABLE myfriends ( last_name VARCHAR(15) NOT NULL, first_name VARCHAR(15) NOT NULL, suffix VARCHAR(5) NULL, sex VARCHAR(1) NULL, city VARCHAR(20) NOT NULL, state VARCHAR(2) NOT NULL, age int ); Swapnali Pawar