CBSE Class 11 Informatics Practices Introduction To SQL
CBSE Class 11 Informatics Practices Introduction To SQL
com
8 Introduction to MySQL
Learning Objectives
v
State what a database is.
v
Express the relationship between a database and table
v
Recognize different parts of a table like Row and Column.
v
Define DBMS related terms like Primary key, Candidate key, Alternate key
etc.
v
List the functions of a DBMS.
v
Write examples of popular DBMS software.
v
State what is MySQL.
v
Install MySQL in a computer.
Most of us keep diaries to store details like names, addresses, birthdays of our
friends. Teachers keep marks registers to keep track of marks secured by their
students. A shopkeeper keeps details of customers who frequently visit his /her
shop in a register. These all are examples of paper-based databases. A database is
an organized collection of related data. However, generally, when we use the term
'database' we think of a computerized database. In this lesson, let us study more
about such databases and numerous tasks that we can do on them.
INFORMATION PRACTICES
INFORMATICS PRACTICES 195
Downloaded from www.studiestoday.com
Downloaded from www.studiestoday.com
The database also records details of all the borrowers, what books they currently have
borrowed and when they are due back.
What is Database Management System(DBMS)?
v
store data in a structured way.
v
query the database (that is, ask questions about the data)
v
sort and manipulate the data in the database
v
validate the data entered and check for inconsistencies
v
produce flexible reports, both on screen and on paper, that make it easy to
comprehend the information stored in the database.
Tables in a Database
The horizontal subset of the Table is known as a Row/Tuple. Each row represents a
record, which is a collection of data about a particular person, place or thing. The vertical
subset of the Table is known as a Column/Attribute. The term field is also often used for
column. Each column has a unique name and the content within it must be of the same
type.
Relational Database
In the database named Learner shown below, the data is organized into separate tables.
Once the tables have been set up, a relationship can be created to link them together.
Such a database that stores data in separate tables that are related through the use of a
common column is called a Relational database.
Participant table
StudentID Activity
84 Swimming
84 Dancing
92 Tennis
100 Golf
100 Cricket
106 Squash
Activity table
Activity Cost
Swimming 2000.00
Dancing 1500.00
Tennis 900.00
Golf 1500.00
Cricket 2000.00
Squash 2500.00
RDBMS Terminology:
Primary key
When you got admission in the school, you were given an Admission number. The
Admission number assigned to you was not assigned to any other student of your school
(it is unique). When patients go to a hospital, each patient is given a unique patient
number. When you go to open an account in the bank, you are given a unique account
number. Admission number, Patient number, Account number are all examples of
Primary key. A primary key is a field in a table that is unique for each record. Every
database table should have a column or a group of columns designated as the primary
key. The value this key holds should be unique for each record in the table.
Some more examples of Primary key are: Accession Number of a Book in the Book table,
Employee ID of an employee in the Employee Table, Item Code of an item in the Stock
table, Flight Number of a flight in the Flight Master Table, etc.
Candidate key
In a table, there may be more than one field that uniquely identifies a record. All such
fields are called candidate keys. A Candidate key is an attribute (or set of attributes) that
uniquely identifies a row. A Primary Key is one of the candidate keys. A table may have
more than one candidate keys but definitely has one and only one primary key.
Example: Consider the following Table, RollNo and Admission_no both may be used to
uniquely identify each row in this Table, so both are candidate keys.
Alternate Key:
Only one of the Candidate keys is selected as the primary key of a table. All other
candidate keys are called Alternate keys. In the above example, if we use one of the
candidate keys, say, Admission_No as the Primary Key, the other Candidate Key RollNo
is the Alternate Key and vice-versa.
Introduction to MySQL:
v
MySQL is released under an open-source license so it is customizable. It
requires no cost or payment for its usage.
v
MySQL has superior speed, is easy to use and is reliable.
v
MySQL uses a standard form of the well-known ANSI-SQL standards.
v
MySQL is a platform independent application which works on many
operating systems like Windows, UNIX, LINUX etc. and has compatibility
with many languages including JAVA , C++, PHP, PERL, etc.
v
MySQL is an easy to install RDBMS and is capable of handling large data sets.
Since MySQL is released under an open-source license, it does not require any cost or
payment for its usage. Any one can download this software from specific location on
Internet. If you want to download, follow the following steps. The step for two most
popular OS platform, Windows and Linux are discussed here.
DOWNLOADING MySQL [Windows Environment]:
INSTALLING MySQL:
After the installation file has finished downloading, double-click it, which begins the
MySQL Setup Wizard.
CONFIGURING MySQL:
At the initial Server Instance Configuration Wizard dialog box, click the "Next" button.
Keep selecting the default options provided in subsequent windows. If the configuration
does not encounter any errors, then information will be prompted that the configuration
file was created, MySQL server was installed and started, and the security settings
applied.
Testing MySQL:
OR
MySQL will prompt a message to provide password (it requires the same password
which was entered during the installation)
Enter Password:****
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.0.51a-community-nt MySQL Community Edition
(GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
Mysql>
Mysql>QUIT
The above steps ensure successful installation and configuration of MySQL database
server. Next time in the MySQL prompt, one can create and use databases, create tables
and execute SQL queries.
Downloading MySQL [Linux Environment]:
Installation of the binary version of MySQL, release 4.0.20, to run on Linux is as follows:
http://dev.mysql.com/downloads/mysql/5.1.html#downloads
# cd mysql
# scripts/mysql_install_db --user=mysql
Preparing db table
Preparing host table
Preparing user table
Preparing func table
...
...
...
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at
https://order.mysql.com
# su -
# cd /usr/local/mysql
# bin/mysqladmin -u root shutdown
040803 23:36:27 mysqld ended
[1]+ Done bin/mysqld_safe --user=mysql
Know more
Visit the following website to find a vast list of free and open source softwares
available:
http://en.wikipedia.org/wiki/List_of_free_and_open_source_software_packages
Summary
v
A database is an organised collection of data.
v
Data is stored in a relational database in one or more tables.
v
A group of rows and columns forms a Table.
v
The horizontal subset of a Table is known as a Row/Tuple.
v
The vertical subset of a Table is known as a Column/Attribute.
v
A Candidate key is an attribute (or a set of attributes) that uniquely identifies a
row. A Primary Key is one of the candidate keys.
v
Only one of the Candidate keys is selected as the primary key of a table. All
other candidate keys are called Alternate keys.
d) field
206 INFORMATICS PRACTICES
Downloaded from www.studiestoday.com
Downloaded from www.studiestoday.com
Exercises
1. Answer the following questions:
a) Define the following terms:
i) Database
ii) Table
iii) Primary key
iv) Candidate key
v) Alternate key
b) What is the relationship between a Database and a Table?
c) What is DBMS? Write names of any two DBMSs.
d) How is data organized in a table?
e) What is a Primary key? What is its purpose in a table?
f) What is MySQL?
2. Distinguish between the following pairs
a) Row and Column
b) Primary key and Candidate key.