Skip to content
← Informatics Practices

Informatics Practices · Class 11 Optional

Ch 7Introduction to Structured Query Language (SQL) — Class 11 Informatics Practices, concept-first.

A database becomes useful only when we can actually create it, fill it with data, and ask it questions. The previous chapter built the theory — what a Relational Database Management System (RDBMS) is and why we need one.

45

Q&A

21

Concepts

~15m

Unit weightage

Start learning — read this chapter →

Key concepts

Hover a concept to preview it and jump to its most relevant Q&A.

Chapter contents

The NCERT structure, section by section. Open a section to see its questions, then read the concept-first solution.

8.1

Introduction

A database becomes useful only when we can actually create it, fill it with data, and ask it questions.

8.2

Structured Query Language (SQL)

The heart of this section is a contrast between two ways of reaching data. In an ordinary file system, there is no built-in way to ask for data — a programmer must write a full application program for…

8.2.1

Installing MySQL

Before any SQL can be written, the software that understands it must be on your machine. MySQL is an open source RDBMS, which means it can be downloaded freely — the official website for this is https…

8.3

Data Types and Constraints in MySQL

This section sets up the two ideas that every table definition rests on: data types and constraints. Both follow directly from how a relational database is organised.

8.3.1

Data type of Attribute

2 Q

A data type indicates the type of data value that an attribute can have — and choosing it is more consequential than it looks, because the data type of an attribute decides which operations can be per…

8.3.2

Constraints

A data type says what kind of value a column may hold; a constraint goes further and restricts which values are acceptable.

8.4

SQL for Data Definition

Everything in a database begins with structure: before a single row of data exists, someone must declare what tables the database contains and what each column of each table looks like.

8.4.1

CREATE Database

A database is a named container managed by the DBMS — tables can only exist inside one. So the first step in building any MySQL project is to create that container, and only after that can relations b…

8.4.2

CREATE Table

3 Q

Creating the database StudentAttendance gives an empty container; the real design work is defining relations (creating tables) inside it.

8.4.3

DESCRIBE Table

After a table has been created, you will often need to check exactly how it was defined — which columns it has, their data types, and which constraints apply to them.

8.4.4

ALTER Table

3 Q

A table's structure is rarely perfect on the first attempt. After creating a table you may realise that an attribute needs to be added or removed, that the data type of an existing attribute must chan…

8.4.5

DROP Statement

Sometimes a table in a database — or the database itself — needs to be removed altogether. The DROP statement does this: it removes a database or a table permanently from the system.

8.5

SQL for Data Manipulation

The CREATE statements of the previous section built the database StudentAttendance with its three relations — STUDENT, GUARDIAN and ATTENDANCE.

8.5.1

INSERTION of Records

3 Q

A newly created table is an empty frame — the INSERT INTO statement is what puts records into it. Its basic syntax supplies one value per attribute:

8.6

SQL for Data Query

Everything so far — creating the database, defining tables, storing and manipulating records — has been preparation for the operation databases really exist for: getting data back out.

8.6.1

SELECT Statement

Creating tables and filling them with records is only half the story — the real power of a database shows when you start asking it questions.

8.6.2

QUERYING using Database OFFICE

20 Q

Every organisation keeps its data in databases organised as related tables. The running example here is a database named OFFICE, which holds several connected tables such as EMPLOYEE and DEPARTMENT.

+Activities1 question
  1. Activity 8.8Compare the output produced by the query in example 8.6 and the following query and differentiate between the OR and AND operators. SELECT *…Preview
+Activities1 question
  1. Activity 8.9Execute the following two queries and find out what will happen if we specify two columns in the ORDER BY clause: SELECT * FROM EMPLOYEE ORD…Preview
+Think & Reflect1 question
  1. Q7Can you think of examples from daily life where storing and querying data in a database can be helpful?Preview
+Think & Reflect1 question
  1. Q8What will happen if in the above query we write "Aaliya" as "AALIYA" or "aaliya" or "AaLIYA"? Will the query generate the same output or an…Preview
+Think & Reflect1 question
  1. Q9When we type first letter of a contact name in our contact list in our mobile phones all the names containing that character are displayed.…Preview
+Worked Examples1 question
  1. Example 8.3Display names of all employees along with their annual salary (Salary*12). While displaying query result, rename EName as Name.Preview
+Worked Examples1 question
  1. Example 8.4Display all the employees who are earning more than 5000 and work in department with DeptId D04.Preview
+Worked Examples1 question
  1. Example 8.5The following query displays records of all the employees except Aaliya.Preview
+Worked Examples1 question
  1. Example 8.6The following query displays name and department number of all those employees who are earning salary between 20000 and 50000 (both values i…Preview
+Worked Examples1 question
  1. Example 8.7The following query displays details of all the employees who are working either in DeptId D01, D02 or D04.Preview
+Worked Examples1 question
  1. Example 8.8The following query displays details of all the employees except those working in department number D01 or D02.Preview
+Worked Examples1 question
  1. Example 8.9The following query displays details of all the employees in ascending order of their salaries.Preview
+Worked Examples1 question
  1. Example 8.10The following query displays details of all the employees in descending order of their salaries.Preview
+Worked Examples1 question
  1. Example 8.11The following query displays details of all those employees who have not been given a bonus. This implies that the bonus column will be blan…Preview
+Worked Examples1 question
  1. Example 8.12The following query displays names of all the employees who have been given a bonus. This implies that the bonus column will not be blank.Preview
+Worked Examples1 question
  1. Example 8.13The following query displays details of all those employees whose name starts with 'K'.Preview
+Worked Examples1 question
  1. Example 8.14The following query displays details of all those employees whose name ends with 'a'.Preview
+Worked Examples1 question
  1. Example 8.15The following query displays details of all those employees whose name consists of exactly 5 letters and starts with any letter but has 'ANY…Preview
+Worked Examples1 question
  1. Example 8.16The following query displays names of all the employees containing 'se' as a substring in name.Preview
+Worked Examples1 question
  1. Example 8.17The following query displays names of all employees containing 'a' as the second character.Preview
8.7

Data Updation and Deletion

Data manipulation does not end with putting records into a table and reading them back. Real data changes constantly: an address is corrected, a phone number is replaced, a person leaves and their rec…

8.7.1

Data Updation

Stored data is rarely final. We may need to make changes in the value(s) of one or more columns of existing records — an address changes, a phone number is replaced, a spelling mistake in a name is di…

8.7.2

Data Deletion

Records do not stay in a table forever. When an entity leaves the picture — a student leaves the school, an employee resigns — its record has to go.

Summary

- A 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 the columns describe the features (attributes) o…

Exercises