CLASS XI Informatics Practices (065) [2025-26] UNIT 3 SQL
Chapter 8 Database concepts
Topics to be covered
» 8.1 Introduction
» 8.2 Structured Query Language (SQL)
» 8.3 Data Types and Constraints in MySQL
» 8.4 Keys in Database
8.1 Introduction
Data: Data is the raw fact and figures. Or Data is a collection of information
Database: A database is a collection of data elements representing real-world information.
A database can be defined as a collection of information organized in such a way that a
computer program is used to quickly retrieve data.
DBMS: A database management system is a software system that enables users to define,
create and maintain the database and provide controlled access to this database.
Relational Database Management System (RDBMS):
There are many RDBMS such as MySQL, Microsoft SQL Server, PostgreSQL, Oracle, etc. that
allow us to create a database consisting of relations and to link one or more relations for
efficient querying to store, retrieve and manipulate data on that database.
In this chapter, we will learn how to create, populate and query database using MySQL.
Tuple: A Tuple is a single row in a database that contains a single record for such a relation.
Field: Field are basically columns in a table with specific information about the data.
Cardinality: The number of unique values in a relational table column relative to the total
number of rows in the table.
Degree: Degree refers to the number of attribute/columns in a table is called as degree.
Domain: A domain is a collection of all possible values from which the values for a given
column or an attribute is drawn.
➢ A domain is said to be atomic if elements are considered to be invisible.
NULL VALUES : If a column in a row has no value, then column is said to be null,or to
contain a null.
➢ You should use a null value when actual value is not known or when a value would not
be meaningful.
Dr. Umme Kulsum [Dep.IT,PGT] Page 1
CLASS XI Informatics Practices (065) [2025-26] UNIT 3 SQL
Comments: A comment is a text that is not executed, it is only for documentation purpose. With
the help of comment in queries user can easily recognize about the data/query passed in SQL.
A) Begin the comment with /* : Proceed with the text of the comment. This text can
span multiple lines. End the comment with */. The opening and terminating characters
need to be separated from the text by a space or a line break.
B) Begin the comment with – – (followed by a space): Proceed with the text of the
comment. This text cannot extend to a new line. End the comment with a line break.
C) Begin the comment with # : Proceed with the text of the comment. This text cannot
extend to a new line. End the comment with a line break.
Need of Database System
The need of database system arose in the early 1960’s in response to the traditional file
processing system.
In the file processing system ,the data is stored in the form of files, and a number of application
programs are written by programmers to add, modify, delete and retrieve data to and from
appropriate files.
8.2 Structured Query Language
➢ (SQL) One has to write application programs to access data in case of a file system.
However, for database management systems there are special kind of programming
languages called query language that can be used to access data from the database.
➢ The Structured Query Language (SQL) is the most popular query language used by
major relational database management systems such as MySQL, ORACLE, SQL
Server, etc.
➢ SQL was initially developed at IBM by Donald D. Chamberlin and Raymond F.
Boyce after learning about the relational model from Edgar F. Codd in the early 1970s.
➢ SQL is easy to learn as the statements comprise of descriptive English words and are
not case sensitive.
➢ We can create and interact with a database using SQL in an efficient and easy way.
➢ The benefit with SQL is that we don’t have to specify how to get the data from the
database. Rather, we simply specify what is to be retrieved, and SQL does the rest.
Although called a query language, SQL can do much more besides querying.
➢ SQL provides statements for defining the structure of the data, manipulating data in the
database, declare constraints and retrieve data from the database in various ways,
depending on our requirements.
Features of MYSQL:
➢ Speed: If the server hardware is optimal, MySQL runs very fast. It supports
clustered servers for demanding applications.
➢ Ease of use: MySQL is high-performance, relatively simple database system.
From the beginning MySQL has typically been configured, monitored, and
managed from the command line.
➢ Cost: MySQL is available free of cost. It is a open source database.
➢ Query Language Support: MySQL understands standards based SQL.
➢ Portability: MySQL provides portability as it has been tested with a broad range
of different compilers and can work on many different platforms.
Dr. Umme Kulsum [Dep.IT,PGT] Page 2
CLASS XI Informatics Practices (065) [2025-26] UNIT 3 SQL
➢ Data Types: MySQL provides many datatypes to support different types of data.
It also supports fixed length and variable-length records.
➢ Security: MySQL offers a privilege and password system that is very flexible
and secure, and that allows host-based verification.
➢ Scalability and limits: MySQL can handle large databases.
Advantages of Databases:
1. Databases reduce the data redundancy to a large extent.
2. Databases can control data inconsistency to a large extent.
3. Databases facilitate sharing of data.
4. Databases enforce standardized structure and format.
5. Databases can ensure data security and privacy.
6. Databases ensure Data independence i.e. any changes to a data structures
are handled by DBMS.
Classification of SQL
In this chapter, we will learn how to create a database using MySQL as the RDBMS software.
We will create a database called StudentAttendance.
We will also learn how to populate database with data, manipulate data in that and retrieve data
from the database through SQL queries.
8.2.1 Installing MySQL
MySQL is an open source RDBMS software which can be easily downloaded from the official
website https:// dev.mysql.com/downloads.
Dr. Umme Kulsum [Dep.IT,PGT] Page 3
CLASS XI Informatics Practices (065) [2025-26] UNIT 3 SQL
After installing MySQL, start MySQL service.
The appearance of mysql> prompt means that MySQL is ready for us to enter SQL statements.
Few rules to follow while writing SQL statements in MySQL:
• SQL is case insensitive. That means name and NAME are same for SQL.
• Always end SQL statements with a semicolon (;)
. • To enter multiline SQL statements, we don’t write ‘;’ after the first line. We put enter to
continue on next line. The prompt mysql> then changes to ‘->’, indicating that statement is
continued to the next line. After the last line, put ‘;’ and press enter.
8.3 Data types and constraints In MySQL
We know that a database consists of one or more relations and each relation (table) is made up
of attributes (column). Each attribute has a data type. We can also specify constraints for each
attribute of a relation.
8.3.1 Data type of Attribute
Data type indicates the type of data value that an attribute can have. The data type of an
attribute decides the operations that can be performed on the data of that attribute.
For example, arithmetic operations can be performed on numeric data but not on character
data.
Commonly used data types in MySQL are numeric types, date and time types, and string
(character and byte)
Dr. Umme Kulsum [Dep.IT,PGT] Page 4
CLASS XI Informatics Practices (065) [2025-26] UNIT 3 SQL
Table 8.1 Commonly used data types in MySQL Data type Description
Data Types Description
CHAR(n) CHAR(n) Specifies character type data of length n where n could be any value
from 0 to 255. CHAR is of fixed length, means, declaring CHAR (10) implies to
reserve spaces for 10 characters. If data does not have 10 characters (for
example, ‘city’ has four characters),
MySQL fills the remaining 6 characters with spaces padded on the right
VARCHAR(n) VARCHAR(n) Specifies character type data of length ‘n’ where n could be any
value from 0 to 65535. But unlike CHAR, VARCHAR is a variable-length data type.
That is, declaring VARCHAR (30) means a maximum of 30 characters can be
stored but the actual allocated bytes will depend on the length of entered string. So
‘city’ in VARCHAR (30) will occupy the space needed to store 4 characters only
INT INT specifies an integer value. Each INT value occupies 4 bytes of storage. The
range of values allowed in integer type are -2147483648 to 2147483647. For
values larger than that, we have to use BIGINT, which occupies 8 bytes.
The BIGINT data type is an integer value from -9,223,372,026,854,775,808 to
BIG INT 9,22,3,372,036854775807. BIGINT Is SQL Server’s largest integer data type. It
uses 8 bytes of storage. BIGINT should be used when values can exceed the
range if INT.
FLOAT FLOAT Holds numbers with decimal points. Each FLOAT value occupies 4 bytes.
A floating-point data type that stores approximate values.
DOUBLE Double: A floating –point data type that stores larger and more precise value than
float.
DATE The DATE type is used for dates in 'YYYY-MM-DD' format. YYYY is the 4 digit
year, MM is the 2 digit month and DD is the 2 digit date. The supported range is
'1000-01-01' to '9999-12-31'.
8.3.2 Constraints
Constraints are certain types of restrictions on the data values that an attribute can have. They
are used to ensure the accuracy and reliability of data. However, it is not mandatory to define
constraint for each attribute of a table .
Table 8.2 lists various SQL constraints.
Dr. Umme Kulsum [Dep.IT,PGT] Page 5
CLASS XI Informatics Practices (065) [2025-26] UNIT 3 SQL
Table 8.2 Commonly used SQL Constraints
Constraint Description
Ensures that a column cannot have NULL values where NULL means
NOT NULL missing/ unknown/not applicable value.
Ensures that all the values in a column are distinct/unique.
UNIQUE
A default value specified for the column if no value is provided.
DEFAULT
The column which can uniquely identify each row or record in a table.
PRIMARY KEY
The column which refers to value of an attribute defined as primary key
FOREIGN KEY in another table
8.4 Keys in Database Management system:
Primary Key
The PRIMARY KEY constraint uniquely identifies each record in a table. Primary keys must
contain UNIQUE values, and cannot contain NULL values.
Candidate Key
A candidate key in a database management system (DBMS) is a unique identifier for a record
within a table that can be chosen as the primary key.
Alternate Key
If a table has more than one candidate key, one of them will become the primary key and rest of
all are called alternate keys. In simple words, any of the candidate key which is not part of
primary key is called an alternate key.
Foreign Key
Dr. Umme Kulsum [Dep.IT,PGT] Page 6
CLASS XI Informatics Practices (065) [2025-26] UNIT 3 SQL
A FOREIGN KEY is a field (or collection of fields) in one table, that refers to the PRIMARY KEY
in another table. The table with the foreign key is called the child table, and the table with the
primary key is called the referenced or parent table.
Composite Key
A composite key in SQL can be defined as a combination of multiple columns, and these
columns are used to identify all the rows that are involved uniquely. Even though a single
column can't identify any row uniquely, a combination of over one column can uniquely identify
any record.
Super Key
Super key is an attribute set that can uniquely identify a tuple. A super key is a superset of
a candidate key. For example: In the above EMPLOYEE table, for(EMPLOEE_ID,
EMPLOYEE_NAME), the name of two employees can be the same, but their EMPLYEE_ID
can't be the same. Hence, this combination can also be a key.
Summary
➢ Database is a collection of related tables.
➢ MySQL is a ‘relational’ DBMS.
➢ A table is a collection of rows and columns, where each row is a record and columns
describe the feature of records.
➢ SQL is the standard language for most RDBMS.
➢ SQL is case insensitive.
Dr. Umme Kulsum [Dep.IT,PGT] Page 7