MySQL Theory Notes
MySQL Theory Notes
3 Define Constraints? Is it mandatory to define constraints for all the attributes in a table?
Constraints are the types of restrictions, which are used to specify rules for the data in a table. Constraints are
used to limit the type of data that can go into a table.
It is not mandatory to define constraints for each attribute of a table.
5. Define Domain.
Domain is a set of values from which an attribute can take value in each row.
For example,
roll number field can have only integer values and so its domain is a set of integer values.
STUDENT
SID ADMNNO SNAME CITY DOB MobileN GENDER
o
101 12365 Ritu Nagpur 2003-10-15 47653433 F
102 23645 Naveen Goa 2004-12-24 48473625 M
103 38746 Rahul Chennai 2001-12-21 84736543 M
104 35463 Rahul Mumbai 2002-12-25 73874653 M
105 87463 Priya Chennai 2005-01-12 98764635 F
11 Differentiate between cardinality and degree of a table with the help of an example.
. Cardinality is defined as the number of tuples/rows in a table.
Degree is the number of attributes/columns in a table.
Table: Account
ACCNo CName
AC100 Sheela
AC101 Darsh
AC102 Kathy
Cardinality of the Account table is: 3
Degree of the Account table is: 2
12 Differentiate between COUNT() and COUNT(*) functions in SQL with an appropriate example.
. COUNT(*) returns the count of all the records/rows in the table,
whereas COUNT () counts the number of non-NULL values in a column that is given as an argument. Hence the
result may differ.
EMP
ENO ENAME JOB SALARY DEPTNO
8499 Akshya NULL 9870 20
8566 Arun SALESMAN 8760 30
8698 Benet MANAGER 5643 20
8912 Surya NULL 3000 10
8369 Smith CLERK 2985 10
e.g. SELECT COUNT(*) FROM EMP; e.g. SELECT COUNT(JOB) FROM EMPL;
Output Output
COUNT(*) COUNT(JOB)
5 3
13 Differentiate ALTER and UPDATE commands.
. ALTER UPDATE
It is a DDL command It is a DML command
It changes the structure of the table. It modifies the data of the table.
Example: Example:
ALTER TABLE student add column average float; UPDATE student set marks=marks+5
WHERE marks <= 50;
17 Which is the pattern-matching operator in SQL and what are the special wildcard character used to match the
. pattern?
LIKE operator is used for substring pattern-matching in SQL.
Percent (%) and underscore( _ ) are the two special wildcard characters used for the pattern match.
The percent (% ) symbol is used to represent zero or more characters.
The underscore ( _ ) symbol is used to represent a single character.
18 What are aggregate functions? List and explain the aggregate functions.
. Aggregate functions also called as group functions, that work on groups of rows rather than on single rows.
These functions are also called as multiple row functions.
By default, Aggregate functions ignores NULL values for calculation.
Aggregate functions:
i. Sum( ) - this function returns the sum of values in given column.
ii. Avg( ) – returns the average of given data.
iii. Min( ) – returns the minimum value from a given data.
iv. Max( ) – returns the maximum value from a given data.
v. Count( ) – returns the number of rows in a given column.