0% found this document useful (0 votes)
353 views13 pages

CBSE Class 11 Informatics Practices Introduction To SQL

This document provides an introduction to MySQL, including: 1) It defines what a database is and explains that MySQL is a database management system (DBMS) used to create and maintain databases. 2) It describes some key database concepts like tables, rows, columns, primary keys, and relational databases. 3) It gives an overview of MySQL, stating that it is an open-source and platform independent RDBMS that can handle large datasets efficiently.

Uploaded by

Avi Meena
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
353 views13 pages

CBSE Class 11 Informatics Practices Introduction To SQL

This document provides an introduction to MySQL, including: 1) It defines what a database is and explains that MySQL is a database management system (DBMS) used to create and maintain databases. 2) It describes some key database concepts like tables, rows, columns, primary keys, and relational databases. 3) It gives an overview of MySQL, stating that it is an open-source and platform independent RDBMS that can handle large datasets efficiently.

Uploaded by

Avi Meena
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 13

Downloaded from www.studiestoday.

com

8 Introduction to MySQL
Learning Objectives

After studying this lesson the students will be able to

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.

These days computerized databases can be seen being used


almost everywhere. The police force uses various computerized
databases to help them track criminals and solve crimes. A
library stores details of all their books, in a computerized
database. When we want to know if a book is in stock, we cannot
only look it up, but can also check when it is due to be returned.

INFORMATION PRACTICES
INFORMATICS PRACTICES 195
Downloaded from www.studiestoday.com
Downloaded from www.studiestoday.com

Chapter-8 Introduction to MySQL

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)?

To create and maintain a database on a computer, we need a database program, called a


Database management system, or DBMS. Database Management System is a software
that enables users to create and maintain databases. Examples of popular DBMSs are
MySQL, PostgreSQL, Microsoft Access, Oracle, Microsoft SQL Server, DB2 and Sybase.
A DBMS gives us tools to:

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

Relational Databases store data or information in tables. A table is similar to a


spreadsheet where data is stored in rows and columns. A table refers to a two
dimensional representation of data using rows and columns. For example, consider the
following table named Customer with details about customers:
Table: Customer Column Row

Customer_ID FirstName LastName Address Telephone No


101 Prachi Mehra 145, Mahatma Avenue, 9178908767
Delhi
102 Vinay Ahlurkar 76-A/32, Adarsh Nagar, 9278906351
Delhi
103 Venu Magalam C-6, Kanthi Nagar, 9323764561
Delhi
104 Neeza Ali B-6-B,Fateh Nagar, 9143347330
Meerut

196 INFORMATICS PRACTICES


Downloaded from www.studiestoday.com
Downloaded from www.studiestoday.com

Chapter-8 Introduction to MySQL

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.

Student table Database : Learner


StudentName StudentID
K.S. Lakshmi 84
Ankita Matta 100
Himali Shah 92
Arushi Goel 106

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

INFORMATICS PRACTICES 197


Downloaded from www.studiestoday.com
Downloaded from www.studiestoday.com

Chapter-8 Introduction to MySQL

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.

The purpose of a primary key is to uniquely identify each record in a table.

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.

Admission_No RollNo Name Class Sec Dues

2301 1 Simran Chadha 11 A 23

1501 2 Ajay Kartik 11 B 15

1678 3 Vanshay Chawla 11 A 20

7003 4 Vibhor Madan 11 C 15

Alternate Key:

Only one of the Candidate keys is selected as the primary key of a table. All other

198 INFORMATICS PRACTICES


Downloaded from www.studiestoday.com
Downloaded from www.studiestoday.com

Chapter-8 Introduction to MySQL

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:

The software required to manipulate relational databases is known as Relational


Database Management System (RDBMS) . Popular RDBMSs include MySQL, Oracle,
Sybase, DB2, MS SQL Server.

MySQL is a relational database management system (RDBMS). It is pronounced as "My


Sequel". MySQL was originally founded and developed in Sweden by David Axmark,
Allan Larsson and Michael Widenius, who had worked together since the 1980s.
Characteristics of 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]:

Installation file for MySQL may be downloaded from the link:


http://dev.mysql.com/downloads/mysql/5.1.html#downloads

(Choose appropriate download link as per the operating system)

INFORMATICS PRACTICES 199


Downloaded from www.studiestoday.com
Downloaded from www.studiestoday.com

Chapter-8 Introduction to MySQL

Click on the "Download" button


for the Community Server and
choose from the list of supported
platforms (i.e., operating
systems that it will run on),
which include 32-bit and 64-bit
Windows, several different
Linux, Solaris, Mac OS X, and a
few others.

INSTALLING MySQL:

After the installation file has finished downloading, double-click it, which begins the
MySQL Setup Wizard.

At the welcome dialog box, click the "Next" button.

200 INFORMATICS PRACTICES


Downloaded from www.studiestoday.com
Downloaded from www.studiestoday.com

Chapter-8 Introduction to MySQL

The MySQL Setup Wizard


allows us to choose the
installation directory on the
computer, and whether or not to
have optional components
installed. In the "Setup Type"
dialog box, choose "Typical"
from the three options. MySQL
will be installed in the default
directory, "C:\Program
Files\MySQL\MySQL Server.
Click the "Next" button.

Now it is ready to install MySQL's files. Click the "Install" button.

After the Setup is complete, we should configure the new server.

INFORMATICS PRACTICES 201


Downloaded from www.studiestoday.com
Downloaded from www.studiestoday.com

Chapter-8 Introduction to MySQL

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.

Note: In the process of configuration of MySQL, a prompt for password will be


displayed - Here you should enter a password and remember this password, as it will be
required each time to start MySQL

202 INFORMATICS PRACTICES


Downloaded from www.studiestoday.com
Downloaded from www.studiestoday.com

Chapter-8 Introduction to MySQL

Testing MySQL:

Follow the steps to start MySQL


Start> Programs>MySQL>….>MySQL Command Line Client

OR

Goto the folder


C:\Program Files\MySQL\MySQL Server 5.1\bin [Assuming C:\ drive
as the drive having MySQL]

And Click on the file


MySQL.EXE

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>

To exit from MySQL, type QUIT or EXIT

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:

Installation file for MySQL may be downloaded from the link:

INFORMATICS PRACTICES 203


Downloaded from www.studiestoday.com
Downloaded from www.studiestoday.com

Chapter-8 Introduction to MySQL

http://dev.mysql.com/downloads/mysql/5.1.html#downloads

(Choose appropriate download link as per the desired operating system)


Create MySQL User Account:
# cd /usr/local
# groupadd mysql
# useradd -c "MySQL Software Owner" -g mysql mysql
# passwd mysql
Changing password for user mysql.
password: all authentication tokens updated successfully.

Installing Binary Version:

Unzip the files and change the directory to mysql

# 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

204 INFORMATICS PRACTICES


Downloaded from www.studiestoday.com
Downloaded from www.studiestoday.com

Chapter-8 Introduction to MySQL

Start and Stop The Database Software:


Starting the MySQL Database
# su -
# cd /usr/local/mysql
# bin/mysqld_safe --user=mysql &

Starting mysqld daemon with databases from /usr/local/mysql/data


Stopping the MySQL Database

# 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.

INFORMATICS PRACTICES 205


Downloaded from www.studiestoday.com
Downloaded from www.studiestoday.com

Chapter-8 Introduction to MySQL

Multiple Choice Questions


1. A relation can have only one ________ key and may have more than one _______
keys.
a) Primary, Candidate
b) Candidate, Alternate
c) Candidate, Primary
d) Alternate, Candidate
2. The vertical subset of a table is known as:
a) Tuple
b) Row
c) Attribute
d) Relation
3. If software is released under open source, it means:
a) It is expensive.
b) Its source code is available to the user.
c) It belongs to a company.
d) It is a DBMS.
4. Which of the following columns in a Student table can be used as the primary
key?
a) Class
b) Section
c) First Name
d) Admission No
5. A tuple is also known as a ___________________________ .
a) table
b) relation
c) row

d) field
206 INFORMATICS PRACTICES
Downloaded from www.studiestoday.com
Downloaded from www.studiestoday.com

Chapter-8 Introduction to MySQL

6. An attribute is also known as a_________________________.


a) table
b) relation
c) row
d) column
7. A field or a combination of fields in a table that has a unique value for each row is
called:
a) Candidate key.
b) Foreign key.
c) Main key.
d) Alternate key.

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.

INFORMATICS PRACTICES 207


Downloaded from www.studiestoday.com

You might also like