12 MYSQL_Revision
12 MYSQL_Revision
MYSQL
It is freely available open source Relational Database Management System (RDBMS) that uses Structured Query
Language(SQL). In MySQL database , information is stored in Tables. A single MySQL database can contain many
tables at once and store thousands of individual records.
SQL (Structured Query Language)
SQL is a language that enables you to create and operate on relational databases, which are sets of
related information stored in tables.
6. Primary Key :This refers to a set of one or more attributes that can uniquely identify tuples within the relation.
7. Candidate Key :All attribute combinations inside a relation that can serve as primary key are candidate keys(as
these are candidates for primary key position).
8. Alternate Key :A candidate key that is not primary key, is called an alternate key.
9. Foreign Key :A non-key attribute, whose values are derived from the primary key of some other table, is
known as foreign key in its current table.
REFERENTIAL INTEGRITY
- A referential integrity is a system of rules that a DBMS uses to ensure that relationships between records in
related tables are valid, and that users don’t accidentally delete or change related data. This integrity
is ensured by foreign key.
1/30
2. Data Manipulation Language(DML) Commands
Commands that allow you to perform data manipulation e.g., retrieval, insertion, deletion and modification
of data stored in a database.
MySQL ELEMENTS
LITERALS
It refer to a fixed data value. This fixed data value may be of character type or numeric type. For example,
‘replay’ , ‘Raj’, ‘8’ , ‘306’ are all character literals.
Numbers not enclosed in quotation marks are numeric literals. E.g. 22 , 18 , 1997 are all numeric literals.
Numeric literals can either be integer literals i.e., without any decimal or be real literals i.e. with a decimal point
e.g. 17 is an integer literal but 17.0 and 17.5 are real literals.
DATA TYPES
Data types are means to identify the type of data and associated operations for handling it. MySQL data
types are divided into three categories:
Numeric
Date and time
String types
DATABASE COMMNADS
3/30
e.g. to enter a row into EMPLOYEE table (created above), we write command as :
INSERT INTO employee
VALUES(1001 , ‘Ravi’ , ‘M’ , ‘E4’ , 50000);
OR
INSERT INTO employee (ECODE , ENAME , GENDER , GRADE , GROSS)
VALUES(1001 , ‘Ravi’ , ‘M’ , ‘E4’ , 50000);
In order to insert another row in EMPLOYEE table , we write again INSERT command :
INSERT INTO employee
VALUES(1002 , ‘Akash’ , ‘M’ , ‘A1’ , 35000);
- To insert value NULL in a specific column, we can type NULL without quotes and NULL will be inserted in that
column. E.g. in order to insert NULL value in ENAME column of above table, we write INSERT command as :
e.g. In order to retrieve everything from Employee table, we write SELECT command as :
SELECT * FROM Employee ;
EMPLOYEE
ECODE ENAME GENDER GRADE GROSS
1001 Ravi M E4 50000
1002 Akash M A1 35000
1004 NULL M B2 38965
4/30
SELECTING PARTICULAR COLUMNS
EMPLOYEE
ECODE ENAME GENDER GRADE GROSS
1001 Ravi M E4 50000
1002 Akash M A1 35000
1004 Neela F B2 38965
1005 Sunny M A2 30000
1006 Ruby F A1 45000
1009 Neema F A2 52000
- A particular column from a table can be selected by specifying column-names with SELECT command. E.g. in
above table, if we want to select ECODE and ENAME column, then command is :
SELECT ECODE , ENAME
FROM EMPLOYEE ;
E.g.2 in order to select only ENAME, GRADE and GROSS column, the command is :
SELECT ENAME , GRADE , GROSS
FROM EMPLOYEE ;
5/30
USING COLUMN ALIASES
- The columns that we select in a query can be given a different name, i.e. column alias name for output purpose.
Syntax :
SELECT <columnname>AS column alias ,<columnname>AS column alias …..
FROM <tablename> ;
e.g. In output, suppose we want to display ECODE column as EMPLOYEE_CODE in output , then command is :
SELECT ECODE AS “EMPLOYEE_CODE”
FROM EMPLOYEE ;
e.g. to display ECODE, ENAME and GRADE of those employees whose salary is between 40000 and 50000,
command is:
SELECT ECODE , ENAME ,GRADE
FROM EMPLOYEE
WHERE GROSS BETWEEN 40000 AND50000 ;
Output will be :
- The NOT IN operator finds rows that do not match in the list. E.g.
SELECT * FROM EMPLOYEE
WHERE GRADE NOT IN (‘A1’ , ‘A2’);
Output will be :
6/30
e.g. to display names of employee whose name starts with R in EMPLOYEE table, the command is :
SELECT ENAME
FROM EMPLOYEE
WHERE ENAME LIKE ‘R%’ ;
Output will be :
ENAME
Ravi
Ruby
Output will be :
Output will be :
7/30
SORTING RESULTS
Whenever the SELECT query is executed , the resulting rows appear in a predecidedorder.TheORDER BY clause allow
sorting of query result. The sorting can be done either in ascending or descending order, the default is ascending.
e.g. to display the details of employees in EMPLOYEE table in alphabetical order, we use command :
SELECT *
FROM EMPLOYEE
ORDER BY ENAME ;
Output will be :
ECODE ENAME GENDER GRADE GROSS
1002 Akash M A1 35000
1004 Neela F B2 38965
1009 Neema F A2 52000
1001 Ravi M E4 50000
1006 Ruby F A1 45000
1005 Sunny M A2 30000
e.g. display list of employee in descending alphabetical order whose salary is greater than 40000.
SELECT ENAME FROM
EMPLOYEE WHERE
GROSS > 40000
ORDER BY ENAME desc ;
Output will be :
ENAME
Ravi
Ruby
Neema
e.g. to change the salary of employee of those in EMPLOYEE table having employee code 1009 to 55000.
UPDATE EMPLOYEE
SET GROSS = 55000
WHERE ECODE = 1009 ;
UPDATING MORE THAN ONE COLUMNS
e.g. to update the salary to 58000 and grade to B2 for those employee whose employee code is 1001.
UPDATE EMPLOYEE
SET GROSS = 58000, GRADE=’B2’
WHERE ECODE = 1009 ;
8/30
OTHER EXAMPLES
e.g.1. Increase the salary of each employee by 1000 in the EMPLOYEE table.
UPDATE EMPLOYEE
SET GROSS = GROSS +100 ;
e.g.2. Double the salary of employees having grade as ‘A1’ or ‘A2’ .
UPDATE EMPLOYEE
SET GROSS = GROSS * 2 ;
WHERE GRADE=’A1’ OR GRADE=’A2’ ;
e.g.3. Change the grade to ‘A2’ for those employees whose employee code is 1004 and name is Neela.
UPDATE EMPLOYEE
SET GRADE=’A2’
WHERE ECODE=1004 AND GRADE=’NEELA’ ;
So if we do not specify any condition with WHERE clause, then all the rows of the table will be deleted. Thus
above line will delete all rows from employee table.
DROPPING TABLES
The DROP TABLE command lets you drop a table from the database. The syntax of DROP TABLE command is :
DROP TABLE <tablename> ;
e.g. to drop a table employee, we need to write :
DROP TABLE employee ;
Once this command is given, the table name is no longer recognized and no more commands can be given on that table.
After this command is executed, all the data in the table along with table structure will be deleted.
9/30
ALTER TABLE COMMAND
The ALTER TABLE command is used to change definitions of existing tables.(adding columns,deleting columns
etc.). The ALTER TABLE command is used for :
1. Adding columns to a table
2. Modifying column-definitions of a table.
3. Deleting columns of a table.
4. Adding constraints to table.
5. Enabling/Disabling constraints.
To add a column to a table, ALTER TABLE command can be used as per following syntax:
However if you specify NOT NULL constraint while adding a new column, MySQL adds the new column with the
default value of that datatype e.g. for INT type it will add 0 , for CHAR types, it will add a space, and so on.
e.g. Given a table namely Testt with the following data in it.
Col1 Col2
1 A
2 G
Now following commands are given for the table. Predict the table contents after each of the following statements:
(i) ALTER TABLE testt ADD col3 INT ;
(ii) ALTER TABLE testt ADD col4 INT NOT NULL ;
(iii) ALTER TABLE testt ADD col5 CHAR(3) NOT NULL ;
(iv) ALTER TABLE testt ADD col6 VARCHAR(3);
MODIFYING COLUMNS
Column name and data type of column can be changed as per following syntax :
10
/30
e.g.1.In table EMPLOYEE, change the column GROSS to SALARY.
DELETING COLUMNS
To delete a column from a table, the ALTER TABLE command takes the following form :
e.g. to add PRIMARY KEY constraint on column ECODE of table EMPLOYEE , the command is :
ALTER TABLE EMPLOYEE
ADD PRIMARY KEY (ECODE) ;
REMOVING CONSTRAINTS
- To remove primary key constraint from a table, we use ALTER TABLE command
as :
ALTER TABLE <table name>DROP PRIMARY KEY ;
- To remove foreign key constraint from a table, we use ALTER TABLE command
as :
ALTER TABLE <table name>DROP FOREIGN KEY ;
ENABLING/DISABLING CONSTRAINTS
Only foreign key can be disabled/enabled in MySQL.
To disable foreign keys :SET FOREIGN_KEY_CHECKS = 0 ;
To enable foreign keys :SET FOREIGN_KEY_CHECKS = 1 ;
11
/30
INTEGRITY CONSTRAINTS/CONSTRAINTS
- A constraint is a condition or check applicable on a field(column) or set of fields(columns).
- Common types of constraints include :
Columns SID and Last_Namecannot include NULL, while First_Namecan include NULL.
DEFAULT CONSTARINT
The DEFAULT constraint provides a default value to a column when the INSERT INTO statement does not
provide a specific value. E.g.
UNIQUE CONSTRAINT
- The UNIQUE constraint ensures that all values in a column are distinct. In other words, no two rows can
hold the same value for a column with UNIQUE constraint.
12
/30
e.g.
CREATE TABLE Customer
( SID integer Unique
,Last_Namevarchar(30) ,
First_Namevarchar(30) ) ;
Column SID has a unique constraint, and hence cannot include duplicate values. So, if the table already
contains the following rows :
SID Last_NameFirst_Name
1 Kumar Ravi
2 Sharma Ajay
3 Devi Raj
CHECK CONSTRAINT
- The CHECK constraint ensures that all values in a column satisfy certain conditions. Once defined, the table will
only insert a new row or update an existing row if the new value satisfies the CHECK constraint.
e.g.
CREATE TABLE Customer
( SID integer CHECK (SID > 0),
Last_Namevarchar(30) ,
First_Namevarchar(30) ) ;
will result in an error because the values for SID must be greater than 0.
- You can define a primary key in CREATE TABLE command through keywords PRIMARY KEY. e.g.
Or
13
/30
CREATE TABLE Customer
( SID integer,
Last_Namevarchar(30) ,
First_Namevarchar(30),
PRIMARY KEY (SID) ) ;
- The latter way is useful if you want to specify a composite primary key, e.g.
e.g.
Parent Table
TABLE: STUDENT
ROLL_NO NAME CLASS
Primary key
1 ABC XI
2 DEF XII
Here column Roll_No is a foreign key in table SCORE(Child Table) and it is drawing its values from
Primary key (ROLL_NO) of STUDENT table.(Parent Key).
14/30
REFERENCING ACTIONS
Referencing action with ON DELETE clause determines what to do in case of a DELETE occurs in the parent table.
Referencing action with ON UPDATE clause determines what to do in case of a UPDATE occurs in the parent table.
Actions:
1. CASCADE : This action states that if a DELETE or UPDATE operation affects a row from the parent table, then
automatically delete or update the matching rows in the child table i.e., cascade the action to child table.
2. SET NULL :This action states that if a DELETE or UPDATE operation affects a row from the parent table, then
set the foreign key column in the child table to NULL.
3. NO ACTION :Any attempt for DELETE or UPDATE in parent table is not allowed.
4. RESTRICT :This action rejects the DELETE or UPDATE operation for the parent table.
15/30
AGGREGATE / GROUP FUNCTIONS
Aggregate / Group functions work upon groups of rows , rather than on single row, and return one single
output. Different aggregate functions are : COUNT( ) , AVG( ) , MIN( ) , MAX( ) , SUM ( )
Table : EMPL
EMPNOENAMEJOBSALDEPTNO
8369SMITHCLERK298510
8499ANYASALESMAN987020
8566AMIRSALESMAN876030
8698BINAMANAGER564320
8912SURNULL300010
1. AVG( )
This function computes the average of given
data. e.g. SELECT AVG(SAL)
FROM EMPL ;
Output
AVG(SAL)
6051.6
2. COUNT( )
This function counts the number of rows in a given column.
If you specify the COLUMN name in parenthesis of function, then this function returns rows where COLUMN
is not null.
If you specify the asterisk (*), this function returns all rows, including duplicates and nulls.
3. MAX( )
This function returns the maximum value from a given column or expression.
16/30
4. MIN( )
This function returns the minimum value from a given column or expression.
5. SUM( )
This function returns the sum of values in given column or expression.
EMPNOENAMEJOBSALDEPTNO
8369SMITHCLERK298510
8499ANYASALESMAN987020
8566AMIRSALESMAN876030
8698BINAMANAGER564320
17/30
e.g.3. find the average salary of each department.
Sol:
** One thing that you should keep in mind is that while grouping , you should include only those values in the SELECT list that
either have the same value for a group or contain a group(aggregate) function. Like in e.g. 2 given above, DEPTNO column has
one(same) value for a group and the other expression SUM(SAL) contains a group function.
NESTED GROUP
- To create a group within a group i.e., nested group, you need to specify multiple fields in the GROUP BY
expression. e.g. To group records job wise within Deptno wise, you need to issue a query statement like :
SELECT DEPTNO , JOB, COUNT(EMPNO)
FROM EMPL
GROUP BY DEPTNO , JOB ;
Output
MySQL FUNCTIONS
A function is a special type of predefined command set that performs some operation and returns a single
value. Types of MySQL functions : String Functions , Maths Functions and Date & Time Functions.
Table : EMPL
EMPNOENAMEJOBSALDEPTNO
8369SMITHCLERK298510
8499ANYASALESMAN987020
8566AMIRSALESMAN876030
8698BINAMANAGER564320
8912SURNULL300010
STRING FUNCTIONS
1. CONCAT( ) - Returns the Concatenated String.
Syntax :CONCAT(Column1 , Column2 , Column3, …….)
e.g. SELECT CONCAT(EMPNO , ENAME) FROM EMPL WHERE DEPTNO=10;
18/30
Output
CONCAT(EMPNO , ENAME)
8369SMITH
8912SUR
19/30
6. RTRIM( ) – Removes trailing spaces.
e.g. SELECT RTRIM(‘ RDBMS MySQL ’) ;
Output
RTRIM(‘ RDBMS MySQL’)
RDBMS MySQL
7. TRIM( ) – Removes trailing and leading spaces.
e.g. SELECT TRIM(‘ RDBMS MySQL ’) ;
Output
TRIM(‘ RDBMS MySQL’)
RDBMS MySQL
8. LENGTH( ) – Returns the length of a string. e.g.
SELECT LENGTH(“CANDID”) ;
Output
LENGTH(“CANDID”)
6
e.g.2.
SELECT LENGTH(ENAME) FROM EMPL;
Output
LENGTH(ENAME)
5
4
4
4
3
NUMERIC FUNCTIONS
These functions accept numeric values and after performing the operation, return numeric value.
1. MOD( ) – Returns the remainder of given two numbers. e.g. SELECT MOD(11 , 4) ;Output
MOD(11, 4 )
3
20/30
2. POW( ) / POWER( ) - This function returns mni.e , a number m raised to the nthpower.
e.g. SELECT POWER(3,2) ;
Output
POWER(3, 2 )
9
e.g. 2.SELECT ROUND(15.193 , -1); - This will convert the number to nearest ten’s .
Output
ROUND(15.193 , -1)
20
E.g. 2.SELECT TRUNCATE(15.79 , -1); - This command truncate value 15.79 to nearest ten’s place.
Output
TRUNCATE(15.79 , -1)
10
21/30
DATE AND TIME FUNCTIONS
Date functions operate on values of the DATE datatype.
2. DATE( ) – This function extracts the date part from a date. E.g.
SELECT DATE( ‘2016-02-09’) ;
Output
DATE( ‘2016-02-09’)
09
3. MONTH( ) – This function returns the month from the date passed. E.g.
SELECT MONTH( ‘2016-02-09’) ;
Output
MONTH( ‘2016-02-09’)
02
22/30
9. NOW( ) – This function returns the current date and time.
It returns a constant time that indicates the time at which the statement began to
execute.
e.g.SELECT NOW( );
10. SYSDATE( ) – It also returns the current date but it return the time at which SYSDATE( ) executes. It
differs from the behavior for NOW( ), which returns a constant time that indicates the time at which the
statement began to execute.
e.g. SELECT SYSDATE( ) ;
DATABASE TRANSACTIONS
TRANSACTION
A Transaction is a logical unit of work that must succeed or fail in its entirety. This statement
means that a transaction may involve many sub steps, which should either all be carried
out successfully or all be ignored if some failure occurs. A Transaction is an atomic operation which
may not be divided into smaller operations.
Example of a Transaction
Begin transaction
Get balance from account X
Calculate new balance as X – 1000
Store new balance into database file
Get balance from account Y
Calculate new balance as Y + 1000
Store new balance into database file
End transaction
23/30
START TRANSACTION
NO: ROLLBACK
Success?
YES : COMMIT
SET AUTOCOMMIT
By default, MySQL has autocommit ON, which means if you do not start a transaction explicitly through a
BEGIN or STATE TRANSACTION command, then every statement is considered one transaction and is
committed there and then.
You can check the current setting by executing the following statement :
mysql> select @@autocommit ;
@@autocommit
1 1means,autocommitisenabled
To disable autocommit , command is:
SET autocommit = 0 ;
To enable autocommit, command is :
SET autocommit = 1 ;
Q1: Given a table t3(code, grade , value).
1 G 300
2 K 600
3 B 200
Considering table t3, for the following series of statements, determine which changes will
become permanent, and what will be the output produced by last SELECT statement i.e.,
statement 7th.
1. SELECT * FROM T3 ;
2. INSERT INTO t3 VALUES(4, ‘A’ , 100) ;
4. ROLLBACK WORK ;DELETE FROM t3 WHERE CODE = 2;
5. DELETE FROM t3 WHERE CODE = 4;
6. ROLLBACK WORK;
7. SELECT * FROM t3 ;
Q2. Give one difference between ROLLBACK and COMMIT command used in MySQL
Q3. Given below is the ‘Emp’ table :
ENO NAME
1 Anita Khanna
2 Bishmeet Singh
24/30
SET AUTOCOMMIT = 0 ;
INSERT INTO EmpVALUES( 5 , ‘Fazaria’);
COMMIT ;
UPDATE Emp SET NAME = ‘Farzziya’ WHERE ENO = 5;
SAVEPOINTA ;
INSERT INTO EmpVALUES(6 , ‘Richards’);
SAVEPOINTB;
INSERT INTO EmpVALUES(7, ‘Rajyalakshmi’);
SAVEPOINTC ;
ROLLBACK TO B ;
What will be the output of the following SQL query now ?SELECT * FROM Emp ;
Q4. If you have not executed the COMMIT command , executing which command will reverse all
updates made during the current work session in MySQL ?
Q5. What effect does SET AUTOCOMMIT have in transactions ?
Q6. What is a Transaction ? Which command is used to make changes done by a
Transaction permanent on a database?
JOINS
- A join is a query that combines rows from two or more tables. In a join- query, more
than one table are listed in FROM clause.
Table :empl
EMPNO ENAME JOBSAL DEPTNO
8369 SMITHCLERK 2985 10
8499 ANYASALESMAN 9870 20
8566 AMIRSALESMAN 8760 30
8698 BINA MANAGER 5643 20
Table :dept
DEPTNO DNAME LOC
10 ACCOUNTINGNEWDELHI
20 RESEARCH CHENNAI
30 SALES KOLKATA
40 OPERATIONSMUMBAI
This query will give you the Cartesian product i.e. all possible concatenations are formed of all rows of
both the tables EMPL and DEPT. Such an operation is also known as Unrestricted Join. It returns n1 x n2
rows where n1 is number of rows in first table and n2 is number of rows in second table.
25/30
EQUI-JOIN
- The join in which columns are compared for equality, is called Equi - Join. In equi-join,
all the columns from joining table appear in the output even if they are identical.
e.g. SELECT * FROM empl, dept
WHERE empl.deptno = dept.deptno ;
Q: with reference to empl and dept table, find the location of employee SMITH.
ename column is present in empl and loc column is present in dept. In order to obtain the
result, we have to join two tables.
Q: Display details like department number, department name, employee number, employee
name, job and salary. And order the rows by employee number.
SELECT EMPL.deptno, dname,empno,ename,job,sal
FROM EMPL,DEPT
WHERE EMPL.DEPTNO=DEPT.DEPTNO
ORDER BY EMPL.DEPTNO;
26/30
QUALIFIED NAMES
Did you notice that in all the WHERE conditions of join queries given so far, the field(column) names
are given as: <tablename>.<columnname>
This type of field names are called qualified field names. Qualified field names are very useful in
identifying a field if the two joining tables have fields with same time. For example, if we say
deptno field from joining tables empl and dept, you’ll definitely ask- deptnofield of which table
? To avoid such an ambiguity, the qualified field names are used.
TABLE ALIAS
- A table alias is a temporary label given along with table name in FROM clause.
e.g.
SELECT E.DEPTNO, DNAME,EMPNO,ENAME,JOB,SAL
FROM EMPL E, DEPT D
WHERE E.DEPTNO = DEPT.DEPTNO
ORDER BY E.DEPTNO;
In above command table alias for EMPL table is E and for DEPT table , alias is D.
Q: Display details like department number, department name, employee number, employee
name, job and salary. And order the rows by employee number with department number.
These details should be only for employees earning atleastRs. 6000 and of SALES department.
NATURAL JOIN
By default, the results of an equijoin contain two identical columns. One of the two identical
columns can be eliminated by restating the query. This result is called a Natural join.
27/30
LEFT JOIN
- You can use LEFT JOIN clause in SELECT to produce left join
i.e. SELECT <select-list>
FROM <table1> LEFT JOIN
<table2> ON <joining-
condition>;
- When using LEFT JOIN all rows from the first table will be returned whether there are
matches in the second table or not. For unmatched rows of first table, NULL is shown in
columns of second table
S1 S2
Roll_no Name Roll_no Class
1 A 2 III
2 B 4 IX
3 C 1 IV
4 D 3 V
5 E 7 I
6 F 8 II
RIGHT JOIN
- It works just like LEFT JOIN but with table order reversed. All rows from the second
table are going to be returned whether or not there are matches in the first table.
- You can use RIGHT JOIN in SELECT to produce right join
i.e. SELECT <select-list>
FROM <table1> RIGHT JOIN <table2> ON <joining-condition>;
28/30
Table:BRANDItem_C
odeBrand_Name
111 LG
222 Sony
333 HCL
444 IFB
Q: A table “Transport” in a database has degree 3 and cardinality 8. What is the number of
rows and columns in it ?
Q: Table Employee has 4 records and Table Dept has 3 records in it. Mr.Jain wants
to display all information stored in both of these related tables. He forgot to specify equi -
join condition in the query. How many rows will get displayed on execution of this query ?
Q: In a database there are two tables “ITEM” and “CUSTOMER” as shown below:
Table: ITEM Table: CUSTOMER
ID ItemName Company Price
1001 Moisturiser XYZ 40 C_ID CustomerName City ID
1002 Sanitizer LAC 35 01 Samridh Ltd New Delhi 1002
1003 Bath Soap COP 25 05 Big Line Inc Mumbai 1005
1004 Shampoo TAP 95 12 97.8 New Delhi 1001
1005 Lens Solution COP 350 15 Tom N Jerry Bangalore 1003
29/30
Q: Write MySql command to create the Table Product including its Constraints.
Table: PRODUCT
Name of Column Type Size Constraint
P_Id Decimal 4 Primary Key
P_NameVarchar 20
P_CompanyVarchar 20
Price Decimal 8 Not Null
Q: Write a MySQL command for creating a table ‘PAYMENT’ whose structure is given below:
Table : PAYMENT
Field Name Datatype Size Constraint
Loan_number Integer 4 Primary Key
Payment_numberVarchar 3
Payment_date Date Not Null
Payment_amount Integer 8
Q:Write SQL command to create the Table Vehicle with given constraint.
Table : CHALLAN
COLUMN_NAME DATATYPE(SIZE) CONSTRAINT
Challan_No Decimal(10) Primary Key
Ch_DateDate
RegNoChar(10)
Offence Decimal(3)
Q:ConsiderthetablesHANDSETSandCUSTOMERgivenbelow:
Table : Handsets Table: Customer
SetCodeSetNameTouchScreenPhoneCostCustNoSetNoCustAddress
N1 Nokia 2G N 5000 1 N2 Delhi
N2 Nokia 3G Y 8000 2 B1 Mumbai
B1 BlackBerry N 14000 3 N2 Mumbai
4 N1 Kolkata
5 B1 Delhi With
reference to these tables, Write commands in SQL for (i) and (ii) and output for (iii) below:
(i) Display the CustNo, CustAddress and Corresponding SetName for each customer.
(ii) Display the Cusomer Details for each customer who uses a Nokia handset.
(iii) Select Setno, SetNameFrom Handsets, Customer
Where setno =setcode AND custAddress = ‘Delhi’;
Q: In a database there are two tables Company and Model as shown below:
Table : Company Table : Model
CompIDCompNameCompHOContPerson ModelIDCompIDModelCost
1 Titan Okhla CB. Ajit T020 1 2000
2 Maxima ShahdaraV.P.Kohli M032 4 2500
3 Ajanta NajafgarhR.Mehta M059 2 7000
30/30