SlideShare una empresa de Scribd logo
1 de 22
Descargar para leer sin conexión
Chapter - 8
MySQL - REVISION TOUR
1. Database: A database is an organised collection of data.
2. DBMS : Software used to manage database is called Data Base
Management System.
3. Relational Database: A database in which the data is stored in the form
of relations (also called tables) is called a Relational Database. In other
words a Relational Database is a collection of one or more tables.
3. RDBMS: A DBMS used to manage Relational Databases is called an
RDBMS (Relational Data Base Management System). Some popular
RDBMS software available are: Oracle, MySQL.
4. Benefits of using a DBMS are:
a. Redundancy can be controlled
b. Inconsistence can be avoided
c. Data can be shared
d. Security restrictions can be applied.
5. MySQL: It is an Open Source RDBMS Software. It is available free of
cost.
6. Relation/Table: A table refers to a two dimensional representation of
data arranged in columns and rows.
7. Primary Key: The group of one or more columns used to uniquely
identify each row of a relation is called its Primary Key.
8. Candidate Key: A Candidate Key is the one that is capable of becoming
Primary key i.e., a field or attribute that has unique value for each row in
the relation.
9. Alternate Key: A candidate key that is not primary key is called
alternate key.
10. Foreign Key: A non-key attribute, whose values are derived from the
primary key of some other table.
11. Degree : Number of columns in the table.
12. Cardinality: Number of rows in a table is called its cardinality.
13. Tuple: A row of a relation.
14. Attribute: A column of relation.
Working with MySQL
SQL (Structured Query Language): It is the language used to
manipulate and manage databases and tables within them using an RDBMS.
1. DDL (Data Definition Language): All the commands which are used to
create, destroy, or restructure databases and tables come under this
category. Examples - CREATE, DROP, ALTER.
2. DML (Data Manipulation Language): All the commands which are
used to manipulate data within tables come under this category. Examples -
INSERT, UPDATE, DELETE.
3. DCL (Data Control Language): All the commands which are used to
control the access to databases and tables fall under this category.
Examples - GRANT, REVOKE.
1. Command: SELECT DATABASE()
Purpose: Shows the name of the current database
2. Command: SHOW TABLES
Purpose: Shows a list of tables present in the current database.
3. Command: ALTER TABLE
Purpose: Modifies the structure of a table
Syntax: (i) ALTER TABLE <tablename>
ADD <columnname> <datatype>;
(ii) ALTER TABLE <tablename>
DROP <columnname>;
(iii) ALTER TABLE <tablename>
MODIFY <column> <new_definition>;
4. Command : USE
Syntax : USE <databasename>;
Purpose : Open the specified database for use.
5. Command : SHOW TABLES
Purpose : Show a list of tables present in the current database.
6. Eliminating duplicate data – DISTINCT keyword eliminates
duplicate rows form the result of a SELECT command.
(i) Display name of all department (non-redundant)
mysql>Select DISTINCT dept from emp;
7. Command: DESCRIBE
Purpose: Shows the structure of a table.
Example : DESC emp;
Example : DESCRIBE emp;
8. Command: UPDATE
Purpose: Updates/Modifies data in a table
(i) Update emp
SET basic = 16000;
(ii) Update emp
SET basic = 16000
Where emono = 5623;
9. Command: DELETE
Purpose: Deletes data from a table
(i) DELETE FROM EMP ;
(II) DELETE FROM EMP
WHERE EMPNO = 4125;
10 . Performing simple calculations
(i) To calculate 2*8*5
mysql> SELECT 2*8*5;
(ii) To calculate 10% DA of basic
mysql > SELECT basic*10/100 from emp;
11. Using Column Aliases
Example : Select empno As ‘Employee Number’ From emp;
12. Condition based on a Range – The MySQL BETWEEN Condition is
used to retrieve values within a range in a SELECT, UPDATE, or DELETE
statement.
Syntax :
expression BETWEEN value1 AND value2;
Range includes both values.
Example :
(i) Select * from employee
Where basic BETWEEN 15000 AND 20000;
(ii) SELECT rollno, name FROM student
WHERE rollno BETWEEN 10 AND 20;
11. Condition based on a List – The IN operator used to select values
that match any value in a list of Specified values.
Example :
(i) Select ename, basic from emp
Where dept IN ( ‘Accounts’, ‘Sales’, Purchase’);
(ii) SELECT rollno, name FROM student WHERE rollno IN (10, 20, 60);
The NOT IN operator finds rows that do not match in the list
(i) Select ename, basic from emp
Where dept NOT IN ( ‘Accounts’, ‘Sales’, Purchase’);
12. Condition based on Pattern Matches – Keyword LIKE is used for
pattern matching of string data using wildcard characters % and _ .
Percent ( % ) – Matches any substring.
Underscore ( _ ) – to match on a single character.
Example :
(i) Select ename, basic, dept from employee
Where ename LIKE ‘A%’;
(ii) Select ename, basic, dept from employee
Where ename LIKE ‘%S’;
Q- (To display name of those employee whose name are 4 characters long)
(iii) Select ename, basic from employee
Where ename LIKE ‘_ _ _ _’;
(iv) Select ename, basic from employee
Where ename LIKE ‘_J%’;
Q- To Display name of those employees where second last character is “r”
(v) Select ename, basic from employee
Where ename LIKE ‘%r_’;
(vi) Select * from contact
Where mobile LIKE ‘8%’;
13. Searching for NULL
Keyword IS NULL is used to select rows in which the specified column
is NULL.
(i) Select empno, ename, design
From emp
Where Design IS NULL;
(ii) Select empno, ename, design
From emp
Where Design IS NOT NULL;
(Relational operator can’t be used with NULL)
14. Sorting Results – ORDER BY Clause - Used to arrange the selected
rows in ascending or in descending order.
Example
1. To arrange/sort the list of employees in the alphabetical order of their
names.
SELECT * FROM emp;
ORDER BY ename;
2. SELECT * FROM student
WHERE marks>50
ORDER BY name;
Functions in MySQL
Numeric Functions:
1. POWER(x,y) OR POW (x,y) - Returns the value of x raised to the
power of y.
Example :
(i) mysql> SELECT POWER (3,2) "RAISED";
RAISED
9
2. ROUND(x) Rounds the argument x to the nearest INTEGER.
Example
(i) mysql> SELECT ROUND(180.55);
ROUND(180.55)
181
3. ROUND(x,d) Rounds the argument x to d decimal places.
mysql> SELECT ROUND (15.193,1)
ROUND (15.193,1)
15.2
4. TRUNCATE(x,d) Truncates the argument x to d decimal places.
mysql> select truncate(150.292,1);
truncate(150.292,1)
150.2
String Functions:
LENGTH(str) Returns the length of a column or a string in bytes.
2. CONCAT(str1,str2,...) Returns the string that results from
concatenating the arguments. May have one or more arguments.
3. INSTR(str,substr) Returns the position of the first occurrence of
substring <substr> in the string <str>.
4. LOWER(STR) OR LCASE(STR) - Returns the argument <str> in
lowercase. i.e., It changes all the characters of the passed string to
lowercase.
5. UPPER(STR) OR UCASE(STR) - Returns the argument <str> in
uppercase. i.e., It changes all the characters of the passed string to
uppercase.
6. LEFT (STR,N) - Returns the first <n> characters from the string <str>
7. RIGHT(STR,N) - Returns the last <n> characters from the string <str>
8. LTRIM(str) Removes leading spaces, i.e., removes spaces from the left
side of the string <str>.
9. RTRIM(str) Removes trailing spaces, i.e., removes spaces from the right
side of the string <str>.
10. TRIM(str) Removes both leading and trailing spaces from the string str.
With Leading Space
11. SUBSTRING(str,m,n) or SUBSTR(str, m, n) or MID(str,m,n) –
12. ASCII(str) Returns the ASCII value of the first character of the string
<str>. Returns 0 if <str> is the empty string. Returns NULL if <str> is
NULL.
Date and Time Functions
1. CURDATE() - Returns the current date in YYYY-MM-DD format.
2. NOW() - Returns the current date and time in 'YYYY-MM-DD HH:MM:SS'.
3. SYSDATE() - Returns the current date and time in 'YYYY-MM-DD
HH:MM:SS'.
4. DATE(expr) - Extracts the date part of a date or datetime expression.
5. MONTH(date) - Returns the numeric month from the date passed.
6. YEAR(date) - Returns the year for date passed.
7. DAYNAME (date) - It returns the name of the weekday for the specified
date.
8. DAYOFMONTH(date) - Returns the day of the month in the range
0 to 31.
9. DAYOFWEEK (date) - Returns the day of week in number as 1 for
Sunday, 2 for Monday and so on.
10. DAYOFYEAR (date) - Return the day of the year for the given date in
numeric format in the range 1 to 366.
11. Difference between NOW() and SYSDATE()
NOW()- function returns a constant date and time at which the statement started executing.
Sleep(argument) - pauses for the number of seconds given by the
argument.
Sysadate () - to get exact time at which the statement executes.
Q1. If a database “Employee” exists, which MySql command helps you to
start working in that database?
Q2. Sahil created a table in MySql. Later on, he found that there should
have been another column in the table. Which command should he use
to add another column to the table?
Q3. Pooja a student of class XI , created a table “Book” . Price is a column
of this table. To find the details of books whose prices have not been
entered she wrote the following query :
Select * from Books where Price = NULL;
Help Pooja to run the query by removing the errors from the query and
rewriting it.
Q4. Rama is not able to change a value in a column to NULL. What
constraints did she specify when she created the table?
Q5. Distinguish between a Primary key and candidate key with the help of
suitable example of each.
Q6. The LastName column of a table “Directory” is given below :
Last Name
Batra
Sehgal
Bhatia
Sharma
Mehta
Based on this information, find the output of the following quries :
(i) SELECT lastname FROM Directory WHERE lastname like ‘_a%’ ;
(ii) SELECT lastname FROM Directory WHERE lastname not like ‘%a’;
Q7. A table “Stock” in a database has 5 columns and contains 17 records.
What is the degree and cardinality of this table?
Ans5. Candidate key is a column or a group of columns that is
capable of becoming the primary key. A table can have multiple
candidates key but it can have only one primary key.
For example , a table STUDENT contains columns AdmNo, RollNo,
Address, PhoneNo. In the table AdmNo and RollNo (both are
unique for every row in the table.) are candidate keys. Out of
these, any one can be selected as the primary key of the table.
Q8. Explain the purpose of DDL and DML commands used in SQl.
Also give two examples of each.
Ans: DDL (Data Definition Language) – DDL commands are
used to create , destroy and to restructure the database objects.
For example , CREATE, ALTER
DML- DML commands are used to insert , delete, and change data
in the tables.
For Example SELECT, DELETE.
Q9. Write the output of the following SQL queries :
(i) SELECT ROUND(6.5675, 2);
(ii) SELECT TRUNCATE(5.3456,1);
(iii) SELECT DAYOFMONTH(‘2009-08-25);
(iv) SELECT MID(‘Class 12, 2, 3);
Q10. Write an SQL query to create the ‘Menu’ with the following structure.
Field Type Constraint
ItemCode Varchar(5) Primary
KeyItemName Varchar(20)
Cateogry Varchar(20)
Price Decimal(5,2)
Q11. While creating a table ‘Customer’ Simrita forgot to set the primary key
for the table. Give the statement which she should write now to set the
column ‘CustID’ as the primary key of the table?
Ans: ALTER TABLE Customer
ADD PRIMARY KEY (CustId);
Q12. Can a table have multiple primary keys? Can it have multiple foreign
keys?
Q13. In a Student table, out of RollNumber, Name, Address which column
can be set ad Primary key and why?
Q14. A table ‘Customers’ in a database has 5 columns and no rows in it.
What is its cardinality ? What will be its cardinality if 4 rows are added in
the table ?
Q15. What is the purpose of DROP TABLE command in SQL? How is it
different form DELETE command?
Q16. Write an SQL query to create the table ‘TEAMS’ with the following
structure:
Field Type Constraint
TeamCode Varchar(5) Primary Key
TeamName Varchar(20)
TeamLeader Varchar(20)
NoOfMembers Integer
Team_Symbol Char(1) Not Null
Ans :
Q
17. Mr. Satish wants to remove a column AC_Type from Account table.
What MySQL command should he use?
Ans: ALTER TABLE Account DROP COLUMN AC_Type;
OR
ALTER TABLE Account DROP AC_Type;
Q18. Name the commands :
(i) To describe the structure of table
(ii) To delete the table physically.
Q19. Explain the IN clause with example.
Ans: The IN clause is used to specify conditions based on a list. The IN
clause selects values that matches any value present in the list of values.
For example.
SELECT * FROM STUDENT
WHERE GRADE IN (‘A’,’B’,’C’);
Q20. Write the resulting output of the following :
(i) SELECT ROUND(1023.432,1);
(ii) SELECT LENGTH(‘RAMESH SHARMA’);
(iii) SELECT UPPER(‘kv neemuch’);
(iv) SELECT MOD(ROUND(120.60,1),5);
Q21. Write the SQL command to create the table voter including its
constraints.
Column Name Data type Size Constraint Description
V_ID INT 8 Primary key
Vname VARCHAR 25 NOT NULL
Age INT 3 CHECK >17 Age should
not less than
equal to 17
Address VARCHAR 30
Phone VARCHAR 10
Ans: Age INT(3) CHECK Age > 17,
Q22. What is meant by cardinality of a table ? Give an example.
Q23. Ms. Sneha is working in a software company .She works under MySQL
database. She forgot to know the tables which she worked in last week.
What MySQL statement she should use to know the tables?
Q24. A table “Vehicle” in a database has degree 4 and cardinality 7. What is
the number of rows and columns in it ?
Q25. Write the SQL command to create the table EMPLOYEE including its
constraints.
Name of Column Type Constraint
ID INT(4) PRIMARY KEY
First_Name VARCHAR(15) NOT NULL
Last_Name VARCHAR(15) NOT NULL
Salary INT(10) DEFAULT 1000
Ans:
Q26.
Q27.
Q28.
Q29.
30
Chapter8 my sql revision tour

Más contenido relacionado

La actualidad más candente (20)

Constraints In Sql
Constraints In SqlConstraints In Sql
Constraints In Sql
 
Oracle SQL Basics
Oracle SQL BasicsOracle SQL Basics
Oracle SQL Basics
 
DDL And DML
DDL And DMLDDL And DML
DDL And DML
 
SQL Queries
SQL QueriesSQL Queries
SQL Queries
 
SQL - Structured query language introduction
SQL - Structured query language introductionSQL - Structured query language introduction
SQL - Structured query language introduction
 
SQL JOIN
SQL JOINSQL JOIN
SQL JOIN
 
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with ExamplesDML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
 
Structured Query Language (SQL)
Structured Query Language (SQL)Structured Query Language (SQL)
Structured Query Language (SQL)
 
Sql join
Sql  joinSql  join
Sql join
 
Triggers
TriggersTriggers
Triggers
 
Sql dml & tcl 2
Sql   dml & tcl 2Sql   dml & tcl 2
Sql dml & tcl 2
 
Introduction to sql
Introduction to sqlIntroduction to sql
Introduction to sql
 
12 SQL
12 SQL12 SQL
12 SQL
 
Sql operator
Sql operatorSql operator
Sql operator
 
Lab2 ddl commands
Lab2 ddl commandsLab2 ddl commands
Lab2 ddl commands
 
SQL
SQLSQL
SQL
 
Strings in c#
Strings in c#Strings in c#
Strings in c#
 
C++
C++C++
C++
 
Python set
Python setPython set
Python set
 
SQL Views
SQL ViewsSQL Views
SQL Views
 

Destacado

CBSE XII Database Concepts And MySQL Presentation
CBSE XII Database Concepts And MySQL PresentationCBSE XII Database Concepts And MySQL Presentation
CBSE XII Database Concepts And MySQL PresentationGuru Ji
 
Class12 communication concepts
Class12 communication conceptsClass12 communication concepts
Class12 communication conceptsGauri Prajapati
 
Student handbook xii
Student handbook xiiStudent handbook xii
Student handbook xiigeetu84
 
CBSE XII Communication And Network Concepts
CBSE XII Communication And Network ConceptsCBSE XII Communication And Network Concepts
CBSE XII Communication And Network ConceptsGuru Ji
 
BASIC CONCEPTS OF COMPUTER NETWORKS
BASIC CONCEPTS OF COMPUTER NETWORKS BASIC CONCEPTS OF COMPUTER NETWORKS
BASIC CONCEPTS OF COMPUTER NETWORKS Kak Yong
 
Introduction to computer network
Introduction to computer networkIntroduction to computer network
Introduction to computer networkAshita Agrawal
 

Destacado (9)

CBSE XII Database Concepts And MySQL Presentation
CBSE XII Database Concepts And MySQL PresentationCBSE XII Database Concepts And MySQL Presentation
CBSE XII Database Concepts And MySQL Presentation
 
Class12 communication concepts
Class12 communication conceptsClass12 communication concepts
Class12 communication concepts
 
Student handbook xii
Student handbook xiiStudent handbook xii
Student handbook xii
 
GUI programming
GUI programmingGUI programming
GUI programming
 
C++ revision tour
C++ revision tourC++ revision tour
C++ revision tour
 
CBSE XII Communication And Network Concepts
CBSE XII Communication And Network ConceptsCBSE XII Communication And Network Concepts
CBSE XII Communication And Network Concepts
 
Networking ppt
Networking ppt Networking ppt
Networking ppt
 
BASIC CONCEPTS OF COMPUTER NETWORKS
BASIC CONCEPTS OF COMPUTER NETWORKS BASIC CONCEPTS OF COMPUTER NETWORKS
BASIC CONCEPTS OF COMPUTER NETWORKS
 
Introduction to computer network
Introduction to computer networkIntroduction to computer network
Introduction to computer network
 

Similar a Chapter8 my sql revision tour

ADBMS unit 1.pdfsdgdsgdsgdsgdsgdsgdsgdsg
ADBMS unit 1.pdfsdgdsgdsgdsgdsgdsgdsgdsgADBMS unit 1.pdfsdgdsgdsgdsgdsgdsgdsgdsg
ADBMS unit 1.pdfsdgdsgdsgdsgdsgdsgdsgdsgzmulani8
 
DATABASE MANAGMENT SYSTEM (DBMS) AND SQL
DATABASE MANAGMENT SYSTEM (DBMS) AND SQLDATABASE MANAGMENT SYSTEM (DBMS) AND SQL
DATABASE MANAGMENT SYSTEM (DBMS) AND SQLDev Chauhan
 
Sql smart reference_by_prasad
Sql smart reference_by_prasadSql smart reference_by_prasad
Sql smart reference_by_prasadpaddu123
 
Sql smart reference_by_prasad
Sql smart reference_by_prasadSql smart reference_by_prasad
Sql smart reference_by_prasadpaddu123
 
Database COMPLETE
Database COMPLETEDatabase COMPLETE
Database COMPLETEAbrar ali
 
Data Manipulation Language.pptx
Data Manipulation Language.pptxData Manipulation Language.pptx
Data Manipulation Language.pptxEllenGracePorras
 
Its about a sql topic for basic structured query language
Its about a sql topic for basic structured query languageIts about a sql topic for basic structured query language
Its about a sql topic for basic structured query languageIMsKanchanaI
 
23. SQL and Database.pdf
23. SQL and Database.pdf23. SQL and Database.pdf
23. SQL and Database.pdfAmaanRizvi6
 
23. SQL and Database.pdf
23. SQL and Database.pdf23. SQL and Database.pdf
23. SQL and Database.pdfUtkarshGAUTAM49
 

Similar a Chapter8 my sql revision tour (20)

ADBMS unit 1.pdfsdgdsgdsgdsgdsgdsgdsgdsg
ADBMS unit 1.pdfsdgdsgdsgdsgdsgdsgdsgdsgADBMS unit 1.pdfsdgdsgdsgdsgdsgdsgdsgdsg
ADBMS unit 1.pdfsdgdsgdsgdsgdsgdsgdsgdsg
 
SQL PPT.pptx
SQL PPT.pptxSQL PPT.pptx
SQL PPT.pptx
 
DATABASE MANAGMENT SYSTEM (DBMS) AND SQL
DATABASE MANAGMENT SYSTEM (DBMS) AND SQLDATABASE MANAGMENT SYSTEM (DBMS) AND SQL
DATABASE MANAGMENT SYSTEM (DBMS) AND SQL
 
ADVANCE ITT BY PRASAD
ADVANCE ITT BY PRASADADVANCE ITT BY PRASAD
ADVANCE ITT BY PRASAD
 
lect 2.pptx
lect 2.pptxlect 2.pptx
lect 2.pptx
 
Module 3
Module 3Module 3
Module 3
 
sql_data.pdf
sql_data.pdfsql_data.pdf
sql_data.pdf
 
Mysqlppt
MysqlpptMysqlppt
Mysqlppt
 
Sql smart reference_by_prasad
Sql smart reference_by_prasadSql smart reference_by_prasad
Sql smart reference_by_prasad
 
Sql smart reference_by_prasad
Sql smart reference_by_prasadSql smart reference_by_prasad
Sql smart reference_by_prasad
 
Database COMPLETE
Database COMPLETEDatabase COMPLETE
Database COMPLETE
 
Mysqlppt
MysqlpptMysqlppt
Mysqlppt
 
Data Manipulation Language.pptx
Data Manipulation Language.pptxData Manipulation Language.pptx
Data Manipulation Language.pptx
 
Oracle notes
Oracle notesOracle notes
Oracle notes
 
Its about a sql topic for basic structured query language
Its about a sql topic for basic structured query languageIts about a sql topic for basic structured query language
Its about a sql topic for basic structured query language
 
Mysql1
Mysql1Mysql1
Mysql1
 
Oracle
OracleOracle
Oracle
 
sql.pptx
sql.pptxsql.pptx
sql.pptx
 
23. SQL and Database.pdf
23. SQL and Database.pdf23. SQL and Database.pdf
23. SQL and Database.pdf
 
23. SQL and Database.pdf
23. SQL and Database.pdf23. SQL and Database.pdf
23. SQL and Database.pdf
 

Último

ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 

Último (20)

ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 

Chapter8 my sql revision tour

  • 1. Chapter - 8 MySQL - REVISION TOUR 1. Database: A database is an organised collection of data. 2. DBMS : Software used to manage database is called Data Base Management System. 3. Relational Database: A database in which the data is stored in the form of relations (also called tables) is called a Relational Database. In other words a Relational Database is a collection of one or more tables. 3. RDBMS: A DBMS used to manage Relational Databases is called an RDBMS (Relational Data Base Management System). Some popular RDBMS software available are: Oracle, MySQL. 4. Benefits of using a DBMS are: a. Redundancy can be controlled b. Inconsistence can be avoided c. Data can be shared d. Security restrictions can be applied. 5. MySQL: It is an Open Source RDBMS Software. It is available free of cost. 6. Relation/Table: A table refers to a two dimensional representation of data arranged in columns and rows. 7. Primary Key: The group of one or more columns used to uniquely identify each row of a relation is called its Primary Key. 8. Candidate Key: A Candidate Key is the one that is capable of becoming Primary key i.e., a field or attribute that has unique value for each row in the relation. 9. Alternate Key: A candidate key that is not primary key is called alternate key. 10. Foreign Key: A non-key attribute, whose values are derived from the primary key of some other table. 11. Degree : Number of columns in the table. 12. Cardinality: Number of rows in a table is called its cardinality.
  • 2. 13. Tuple: A row of a relation. 14. Attribute: A column of relation. Working with MySQL SQL (Structured Query Language): It is the language used to manipulate and manage databases and tables within them using an RDBMS. 1. DDL (Data Definition Language): All the commands which are used to create, destroy, or restructure databases and tables come under this category. Examples - CREATE, DROP, ALTER. 2. DML (Data Manipulation Language): All the commands which are used to manipulate data within tables come under this category. Examples - INSERT, UPDATE, DELETE. 3. DCL (Data Control Language): All the commands which are used to control the access to databases and tables fall under this category. Examples - GRANT, REVOKE. 1. Command: SELECT DATABASE() Purpose: Shows the name of the current database 2. Command: SHOW TABLES Purpose: Shows a list of tables present in the current database. 3. Command: ALTER TABLE Purpose: Modifies the structure of a table Syntax: (i) ALTER TABLE <tablename> ADD <columnname> <datatype>; (ii) ALTER TABLE <tablename> DROP <columnname>; (iii) ALTER TABLE <tablename> MODIFY <column> <new_definition>; 4. Command : USE Syntax : USE <databasename>; Purpose : Open the specified database for use.
  • 3. 5. Command : SHOW TABLES Purpose : Show a list of tables present in the current database. 6. Eliminating duplicate data – DISTINCT keyword eliminates duplicate rows form the result of a SELECT command. (i) Display name of all department (non-redundant) mysql>Select DISTINCT dept from emp; 7. Command: DESCRIBE Purpose: Shows the structure of a table. Example : DESC emp; Example : DESCRIBE emp; 8. Command: UPDATE Purpose: Updates/Modifies data in a table (i) Update emp SET basic = 16000; (ii) Update emp SET basic = 16000 Where emono = 5623; 9. Command: DELETE Purpose: Deletes data from a table (i) DELETE FROM EMP ; (II) DELETE FROM EMP WHERE EMPNO = 4125; 10 . Performing simple calculations (i) To calculate 2*8*5 mysql> SELECT 2*8*5; (ii) To calculate 10% DA of basic mysql > SELECT basic*10/100 from emp;
  • 4. 11. Using Column Aliases Example : Select empno As ‘Employee Number’ From emp; 12. Condition based on a Range – The MySQL BETWEEN Condition is used to retrieve values within a range in a SELECT, UPDATE, or DELETE statement. Syntax : expression BETWEEN value1 AND value2; Range includes both values. Example : (i) Select * from employee Where basic BETWEEN 15000 AND 20000; (ii) SELECT rollno, name FROM student WHERE rollno BETWEEN 10 AND 20; 11. Condition based on a List – The IN operator used to select values that match any value in a list of Specified values. Example : (i) Select ename, basic from emp Where dept IN ( ‘Accounts’, ‘Sales’, Purchase’); (ii) SELECT rollno, name FROM student WHERE rollno IN (10, 20, 60); The NOT IN operator finds rows that do not match in the list (i) Select ename, basic from emp Where dept NOT IN ( ‘Accounts’, ‘Sales’, Purchase’); 12. Condition based on Pattern Matches – Keyword LIKE is used for pattern matching of string data using wildcard characters % and _ . Percent ( % ) – Matches any substring. Underscore ( _ ) – to match on a single character. Example : (i) Select ename, basic, dept from employee Where ename LIKE ‘A%’; (ii) Select ename, basic, dept from employee Where ename LIKE ‘%S’;
  • 5. Q- (To display name of those employee whose name are 4 characters long) (iii) Select ename, basic from employee Where ename LIKE ‘_ _ _ _’; (iv) Select ename, basic from employee Where ename LIKE ‘_J%’; Q- To Display name of those employees where second last character is “r” (v) Select ename, basic from employee Where ename LIKE ‘%r_’; (vi) Select * from contact Where mobile LIKE ‘8%’; 13. Searching for NULL Keyword IS NULL is used to select rows in which the specified column is NULL. (i) Select empno, ename, design From emp Where Design IS NULL; (ii) Select empno, ename, design From emp Where Design IS NOT NULL; (Relational operator can’t be used with NULL) 14. Sorting Results – ORDER BY Clause - Used to arrange the selected rows in ascending or in descending order. Example 1. To arrange/sort the list of employees in the alphabetical order of their names. SELECT * FROM emp; ORDER BY ename; 2. SELECT * FROM student WHERE marks>50 ORDER BY name;
  • 6. Functions in MySQL Numeric Functions: 1. POWER(x,y) OR POW (x,y) - Returns the value of x raised to the power of y. Example : (i) mysql> SELECT POWER (3,2) "RAISED"; RAISED 9 2. ROUND(x) Rounds the argument x to the nearest INTEGER. Example (i) mysql> SELECT ROUND(180.55); ROUND(180.55) 181 3. ROUND(x,d) Rounds the argument x to d decimal places. mysql> SELECT ROUND (15.193,1) ROUND (15.193,1) 15.2
  • 7. 4. TRUNCATE(x,d) Truncates the argument x to d decimal places. mysql> select truncate(150.292,1); truncate(150.292,1) 150.2 String Functions: LENGTH(str) Returns the length of a column or a string in bytes. 2. CONCAT(str1,str2,...) Returns the string that results from concatenating the arguments. May have one or more arguments.
  • 8. 3. INSTR(str,substr) Returns the position of the first occurrence of substring <substr> in the string <str>. 4. LOWER(STR) OR LCASE(STR) - Returns the argument <str> in lowercase. i.e., It changes all the characters of the passed string to lowercase. 5. UPPER(STR) OR UCASE(STR) - Returns the argument <str> in uppercase. i.e., It changes all the characters of the passed string to uppercase.
  • 9. 6. LEFT (STR,N) - Returns the first <n> characters from the string <str> 7. RIGHT(STR,N) - Returns the last <n> characters from the string <str>
  • 10. 8. LTRIM(str) Removes leading spaces, i.e., removes spaces from the left side of the string <str>. 9. RTRIM(str) Removes trailing spaces, i.e., removes spaces from the right side of the string <str>. 10. TRIM(str) Removes both leading and trailing spaces from the string str. With Leading Space
  • 11. 11. SUBSTRING(str,m,n) or SUBSTR(str, m, n) or MID(str,m,n) –
  • 12. 12. ASCII(str) Returns the ASCII value of the first character of the string <str>. Returns 0 if <str> is the empty string. Returns NULL if <str> is NULL. Date and Time Functions 1. CURDATE() - Returns the current date in YYYY-MM-DD format. 2. NOW() - Returns the current date and time in 'YYYY-MM-DD HH:MM:SS'.
  • 13. 3. SYSDATE() - Returns the current date and time in 'YYYY-MM-DD HH:MM:SS'. 4. DATE(expr) - Extracts the date part of a date or datetime expression. 5. MONTH(date) - Returns the numeric month from the date passed.
  • 14. 6. YEAR(date) - Returns the year for date passed. 7. DAYNAME (date) - It returns the name of the weekday for the specified date. 8. DAYOFMONTH(date) - Returns the day of the month in the range 0 to 31. 9. DAYOFWEEK (date) - Returns the day of week in number as 1 for Sunday, 2 for Monday and so on.
  • 15. 10. DAYOFYEAR (date) - Return the day of the year for the given date in numeric format in the range 1 to 366. 11. Difference between NOW() and SYSDATE() NOW()- function returns a constant date and time at which the statement started executing. Sleep(argument) - pauses for the number of seconds given by the argument.
  • 16. Sysadate () - to get exact time at which the statement executes. Q1. If a database “Employee” exists, which MySql command helps you to start working in that database? Q2. Sahil created a table in MySql. Later on, he found that there should have been another column in the table. Which command should he use to add another column to the table? Q3. Pooja a student of class XI , created a table “Book” . Price is a column of this table. To find the details of books whose prices have not been entered she wrote the following query : Select * from Books where Price = NULL; Help Pooja to run the query by removing the errors from the query and rewriting it. Q4. Rama is not able to change a value in a column to NULL. What constraints did she specify when she created the table? Q5. Distinguish between a Primary key and candidate key with the help of suitable example of each. Q6. The LastName column of a table “Directory” is given below : Last Name
  • 17. Batra Sehgal Bhatia Sharma Mehta Based on this information, find the output of the following quries : (i) SELECT lastname FROM Directory WHERE lastname like ‘_a%’ ; (ii) SELECT lastname FROM Directory WHERE lastname not like ‘%a’; Q7. A table “Stock” in a database has 5 columns and contains 17 records. What is the degree and cardinality of this table? Ans5. Candidate key is a column or a group of columns that is capable of becoming the primary key. A table can have multiple candidates key but it can have only one primary key. For example , a table STUDENT contains columns AdmNo, RollNo, Address, PhoneNo. In the table AdmNo and RollNo (both are unique for every row in the table.) are candidate keys. Out of these, any one can be selected as the primary key of the table. Q8. Explain the purpose of DDL and DML commands used in SQl. Also give two examples of each. Ans: DDL (Data Definition Language) – DDL commands are used to create , destroy and to restructure the database objects. For example , CREATE, ALTER DML- DML commands are used to insert , delete, and change data in the tables. For Example SELECT, DELETE. Q9. Write the output of the following SQL queries : (i) SELECT ROUND(6.5675, 2); (ii) SELECT TRUNCATE(5.3456,1);
  • 18. (iii) SELECT DAYOFMONTH(‘2009-08-25); (iv) SELECT MID(‘Class 12, 2, 3); Q10. Write an SQL query to create the ‘Menu’ with the following structure. Field Type Constraint ItemCode Varchar(5) Primary KeyItemName Varchar(20) Cateogry Varchar(20) Price Decimal(5,2) Q11. While creating a table ‘Customer’ Simrita forgot to set the primary key for the table. Give the statement which she should write now to set the column ‘CustID’ as the primary key of the table? Ans: ALTER TABLE Customer ADD PRIMARY KEY (CustId); Q12. Can a table have multiple primary keys? Can it have multiple foreign keys? Q13. In a Student table, out of RollNumber, Name, Address which column can be set ad Primary key and why? Q14. A table ‘Customers’ in a database has 5 columns and no rows in it. What is its cardinality ? What will be its cardinality if 4 rows are added in the table ? Q15. What is the purpose of DROP TABLE command in SQL? How is it different form DELETE command? Q16. Write an SQL query to create the table ‘TEAMS’ with the following structure: Field Type Constraint TeamCode Varchar(5) Primary Key TeamName Varchar(20) TeamLeader Varchar(20)
  • 19. NoOfMembers Integer Team_Symbol Char(1) Not Null Ans : Q 17. Mr. Satish wants to remove a column AC_Type from Account table. What MySQL command should he use? Ans: ALTER TABLE Account DROP COLUMN AC_Type; OR ALTER TABLE Account DROP AC_Type; Q18. Name the commands : (i) To describe the structure of table (ii) To delete the table physically. Q19. Explain the IN clause with example. Ans: The IN clause is used to specify conditions based on a list. The IN clause selects values that matches any value present in the list of values. For example. SELECT * FROM STUDENT WHERE GRADE IN (‘A’,’B’,’C’); Q20. Write the resulting output of the following : (i) SELECT ROUND(1023.432,1); (ii) SELECT LENGTH(‘RAMESH SHARMA’); (iii) SELECT UPPER(‘kv neemuch’); (iv) SELECT MOD(ROUND(120.60,1),5); Q21. Write the SQL command to create the table voter including its constraints.
  • 20. Column Name Data type Size Constraint Description V_ID INT 8 Primary key Vname VARCHAR 25 NOT NULL Age INT 3 CHECK >17 Age should not less than equal to 17 Address VARCHAR 30 Phone VARCHAR 10 Ans: Age INT(3) CHECK Age > 17, Q22. What is meant by cardinality of a table ? Give an example. Q23. Ms. Sneha is working in a software company .She works under MySQL database. She forgot to know the tables which she worked in last week. What MySQL statement she should use to know the tables? Q24. A table “Vehicle” in a database has degree 4 and cardinality 7. What is the number of rows and columns in it ? Q25. Write the SQL command to create the table EMPLOYEE including its constraints. Name of Column Type Constraint ID INT(4) PRIMARY KEY First_Name VARCHAR(15) NOT NULL Last_Name VARCHAR(15) NOT NULL Salary INT(10) DEFAULT 1000 Ans: