Informatics Practices Chapter 8 4 Study Options Available

Introduction to Structured Query Language (SQL)

CHAPTER PDF

Complete curriculum textbook chapter document for reading and offline study.

Chapter 8 – Introduction to SQL

NOTES

Complete conceptual breakdown, formulas, diagrams, and memory aids.

Chapter 8 – Introduction to SQL | Class XI IP 065
CBSE INFORMATICS PRACTICES · SUBJECT CODE 065 · CLASS XI

Chapter 8 – Introduction to Structured Query Language (SQL)

Complete study notes based on the uploaded 32-page NCERT chapter, with clear concepts, MySQL syntax, worked examples, tables and revision material.

1. Introduction

A Relational Database Management System (RDBMS) allows us to create databases consisting of relations (tables), connect related tables, and store, retrieve and manipulate data. Examples include MySQL, Microsoft SQL Server, PostgreSQL and Oracle.

This chapter uses MySQL to create and work with a school database named StudentAttendance. The example database has three related tables:

TableInformation storedImportant attributes
STUDENTStudent informationRollNumber, SName, SDateofBirth, GUID
GUARDIANGuardian informationGUID, GName, GPhone, GAddress
ATTENDANCEDaily attendanceAttendanceDate, RollNumber, AttendanceStatus

STUDENT.GUID refers to GUARDIAN.GUID. ATTENDANCE.RollNumber refers to STUDENT.RollNumber.

2. Structured Query Language (SQL)

SQL stands for Structured Query Language. It is the standard language used to communicate with relational database systems. SQL is used to define database structures, declare constraints, insert/update/delete records and retrieve information.

Characteristics of SQL

  • Uses descriptive, English-like statements.
  • SQL keywords are case-insensitive: SELECT, Select and select have the same meaning.
  • Each complete statement normally ends with a semicolon (;).
  • Users specify what information is required; the DBMS determines how to retrieve it.
  • SQL does more than querying: it can create and modify database objects and manipulate stored records.

MySQL installation and prompt

MySQL is open-source RDBMS software. The textbook gives the official download site as https://dev.mysql.com/downloads. After installation, start the MySQL service and open the MySQL shell/client. The mysql> prompt indicates readiness to accept SQL statements. For a multi-line statement, MySQL may show -> as the continuation prompt; enter the semicolon after the final line.

mysql> SHOW DATABASES;
mysql> USE StudentAttendance;
mysql> SHOW TABLES;
Use one consistent naming convention. Database/table name case-sensitivity can depend on the operating system and MySQL configuration.

3. Data Types in MySQL

A data type specifies what kind of value an attribute (column) can store. It determines the valid values and the operations meaningful for that attribute.

TypeDescriptionExample / use
CHAR(n)Fixed-length character string. The chapter describes n from 0 to 255. Shorter values are padded with spaces.CHAR(10) for a fixed-length code.
VARCHAR(n)Variable-length character string, up to the declared maximum. Actual storage depends on the entered string length. Maximum depends on MySQL limits.VARCHAR(30) for names.
INTInteger. Textbook: 4 bytes; −2147483648 to 2147483647.Roll number, count.
BIGINTLarger integer type. Textbook: 8 bytes.Very large integer values.
FLOATNumber that can contain a decimal point. Textbook: 4 bytes.Decimal measurements.
DATEDate in YYYY-MM-DD format. Textbook range: 1000-01-01 to 9999-12-31.'2003-05-15'

CHAR versus VARCHAR

CHAR – fixed length

CHAR(10) reserves a fixed 10-character field. A value such as CITY is padded to the defined length.

VARCHAR – variable length

VARCHAR(30) allows up to 30 characters, but stores according to the actual string length.

Choosing data types in the school database

  • RollNumber INT – numeric roll number.
  • SName VARCHAR(20) – names have varying lengths.
  • SDateofBirth DATE – date value.
  • GUID CHAR(12) – fixed-length 12-character identifier.
  • Phone numbers are identifiers, not quantities for arithmetic. Store them as character data (for example CHAR(10)) to preserve leading zeroes.

4. Constraints in MySQL

A constraint is a restriction on the values that an attribute can contain. Constraints help maintain accuracy and reliability. Not every column must have a constraint.

ConstraintPurposeExample
NOT NULLColumn cannot contain NULL.SName VARCHAR(20) NOT NULL
UNIQUEPrevents duplicate values in a column.GPhone CHAR(10) UNIQUE
DEFAULTSupplies a value when one is not provided.Status CHAR(1) DEFAULT 'P'
PRIMARY KEYUniquely identifies each row; cannot be NULL.PRIMARY KEY (RollNumber)
FOREIGN KEYRefers to a key in another table to establish a relationship.FOREIGN KEY (GUID) REFERENCES GUARDIAN(GUID)

A primary key has the essential properties of uniqueness and non-NULL values. The combination of UNIQUE and NOT NULL enforces those properties, while PRIMARY KEY explicitly declares the table's identifier. A foreign-key value must match an existing referenced key unless it is NULL and NULL is permitted.

5. SQL for Data Definition – DDL

Data Definition Language (DDL) contains commands for defining database and table structures (schemas), data types and constraints.

  • CREATE DATABASE – creates a database.
  • CREATE TABLE – creates a table.
  • DESCRIBE / DESC – displays table structure.
  • ALTER TABLE – changes table structure.
  • DROP TABLE / DROP DATABASE – permanently removes objects.

5.1 CREATE DATABASE

CREATE DATABASE database_name;

Example:

CREATE DATABASE StudentAttendance;

5.2 USE database

Select the database before creating tables or querying it:

USE StudentAttendance;

5.3 SHOW DATABASES and SHOW TABLES

SHOW DATABASES;
USE StudentAttendance;
SHOW TABLES;

SHOW DATABASES; lists databases on the server. SHOW TABLES; lists tables in the currently selected database. A newly created database initially has no tables.

6. CREATE TABLE

CREATE TABLE defines a relation by specifying its column names, data types and optional constraints. The number of columns is the degree of the relation.

CREATE TABLE table_name (
    attribute1 datatype constraint,
    attribute2 datatype constraint,
    attribute3 datatype constraint
);

6.1 Create STUDENT

CREATE TABLE STUDENT (
    RollNumber INT,
    SName VARCHAR(20),
    SDateofBirth DATE,
    GUID CHAR(12),
    PRIMARY KEY (RollNumber)
);

RollNumber uniquely identifies a student. SName stores a variable-length name; SDateofBirth stores a date; GUID stores a 12-character guardian identifier.

6.2 School table design from the chapter

TableAttributeTypeConstraint / role
STUDENTRollNumberINTPRIMARY KEY
STUDENTSNameVARCHAR(20)NOT NULL
STUDENTSDateofBirthDATENOT NULL
STUDENTGUIDCHAR(12)FOREIGN KEY
GUARDIANGUIDCHAR(12)PRIMARY KEY
GUARDIANGNameVARCHAR(20)NOT NULL
GUARDIANGPhoneCHAR(10)UNIQUE; may be NULL
GUARDIANGAddressVARCHAR(30)NOT NULL
ATTENDANCEAttendanceDateDATEPart of composite primary key
ATTENDANCERollNumberINTPart of composite primary key; FOREIGN KEY
ATTENDANCEAttendanceStatusCHAR(1)NOT NULL (P/A)

Complete example with constraints declared during table creation:

CREATE TABLE GUARDIAN (
    GUID CHAR(12) PRIMARY KEY,
    GName VARCHAR(20) NOT NULL,
    GPhone CHAR(10) UNIQUE,
    GAddress VARCHAR(30) NOT NULL
);

CREATE TABLE ATTENDANCE (
    AttendanceDate DATE,
    RollNumber INT,
    AttendanceStatus CHAR(1) NOT NULL,
    PRIMARY KEY (AttendanceDate, RollNumber)
);

The ATTENDANCE primary key is composite because the same student has many attendance dates and each date has many students. The pair (AttendanceDate, RollNumber) identifies one attendance entry.

7. DESCRIBE / DESC Table

Use DESCRIBE to see the structure of a table. MySQL also supports the short form DESC.

DESCRIBE STUDENT;
-- Short form:
DESC STUDENT;

The output includes Field (column name), Type (data type), Null (whether NULL is allowed), Key, Default and Extra. DESC is for viewing structure; it does not display table records.

SELECT * FROM STUDENT;
Exam distinction: DESC STUDENT; describes the table. SELECT * FROM STUDENT; displays its records.

8. ALTER TABLE

ALTER TABLE changes the structure of an existing table: add or remove a column, modify a data type, or add/remove constraints.

8.1 Add a primary key

ALTER TABLE GUARDIAN
ADD PRIMARY KEY (GUID);

ALTER TABLE ATTENDANCE
ADD PRIMARY KEY (AttendanceDate, RollNumber);

8.2 Add a foreign key

ALTER TABLE table_name
ADD FOREIGN KEY (column_name)
REFERENCES referenced_table (referenced_column);

Example – STUDENT.GUID refers to GUARDIAN.GUID:

ALTER TABLE STUDENT
ADD FOREIGN KEY (GUID)
REFERENCES GUARDIAN (GUID);

Before adding a foreign key, the referenced table must exist; the referenced column must be an eligible key; and the referencing and referenced columns should have matching data types and sizes.

8.3 Add UNIQUE constraint

ALTER TABLE GUARDIAN
ADD UNIQUE (GPhone);

8.4 Add a new column

ALTER TABLE GUARDIAN
ADD income INT;

8.5 Modify a column's data type/size

ALTER TABLE GUARDIAN
MODIFY GAddress VARCHAR(40);

8.6 Make a column NOT NULL

ALTER TABLE STUDENT
MODIFY SName VARCHAR(20) NOT NULL;

When using MODIFY, specify the data type along with the constraint.

8.7 Set a DEFAULT value

ALTER TABLE STUDENT
MODIFY SDateofBirth DATE DEFAULT '2000-05-15';

8.8 Remove a column

ALTER TABLE GUARDIAN
DROP income;

8.9 Remove a primary key

ALTER TABLE GUARDIAN
DROP PRIMARY KEY;
Changing or dropping keys can affect foreign-key relationships. Check dependent constraints and existing records before altering a production database.

9. DROP Statement

DROP permanently removes a database object. It cannot be treated like deleting one row.

Drop a table

DROP TABLE table_name;
DROP TABLE ATTENDANCE;

Drop a database

DROP DATABASE database_name;
DROP DATABASE StudentAttendance;
Caution: Dropping a database removes all tables within it. DROP is destructive; use it only when the object is no longer needed and suitable backups exist.

10. INSERT – Insertion of Records

INSERT INTO adds new rows to a table.

10.1 Insert values for every column in table order

INSERT INTO table_name
VALUES (value1, value2, ...);
INSERT INTO GUARDIAN
VALUES ('444444444444', 'Amit Ahuja',
        '5711492685', 'G-35, Ashok Vihar, Delhi');

When column names are omitted, provide one value for every column in the correct order.

10.2 Insert into selected columns

INSERT INTO table_name (column1, column2, ...)
VALUES (value1, value2, ...);
INSERT INTO GUARDIAN (GUID, GName, GAddress)
VALUES ('333333333333', 'Danny Dsouza',
        'S-13, Ashok Village, Daman');

GPhone is omitted, so it receives NULL or its permitted default value.

10.3 Insert a student

INSERT INTO STUDENT
VALUES (1, 'Atharv Ahuja', '2003-05-15',
        '444444444444');

-- Equivalent form with column names
INSERT INTO STUDENT
(RollNumber, SName, SDateofBirth, GUID)
VALUES (1, 'Atharv Ahuja', '2003-05-15',
        '444444444444');

10.4 Insert NULL in a permitted foreign-key column

INSERT INTO STUDENT
VALUES (3, 'Taleem Shah', '2002-02-28', NULL);

-- Or omit the GUID column
INSERT INTO STUDENT (RollNumber, SName, SDateofBirth)
VALUES (3, 'Taleem Shah', '2002-02-28');

INSERT rules

  1. Text and date values are enclosed in single quotes.
  2. When no column list is supplied, values must match all columns in table order.
  3. When a column list is supplied, values must follow that list's order.
  4. Use SQL NULL for a missing value if allowed; do not confuse it with the text 'NULL'.
  5. Insert parent/reference records before child records that use their keys as foreign keys.
  6. A duplicate primary-key value is not allowed.
Recommended practice: include column names in INSERT statements to make them clearer and less dependent on table column order.

11. SQL for Data Query – SELECT

SELECT retrieves information from tables. Its output is displayed in tabular form.

SELECT column1, column2, ...
FROM table_name
WHERE condition;

SELECT specifies the columns, FROM identifies the source table, and optional WHERE filters rows.

11.1 Display all columns

SELECT * FROM STUDENT;

The asterisk (*) represents all columns.

11.2 Display selected columns

SELECT SName, SDateofBirth
FROM STUDENT;

11.3 Retrieve a particular student

SELECT SName, SDateofBirth
FROM STUDENT
WHERE RollNumber = 1;

12. Querying using the OFFICE Database

The textbook's OFFICE database contains an EMPLOYEE table and related tables such as DEPARTMENT. DeptId in EMPLOYEE identifies the department and acts as a foreign key.

EmpNoEnameSalaryBonusDeptId
101Aaliya10000234D02
102Kritika60000123D01
103Shabbir45000566D01
104Gurpreet19000565D04
105Joseph34000875D03
106Sanya48000695D02
107Vergese15000NULLD01
108Nachaobi29000NULLD05
109Daribha42000NULLD04
110Tanya50000467D05

Use these sample records to understand the SELECT examples that follow.

13. DISTINCT Clause and Column Aliases

13.1 Rename a displayed column using AS

AS assigns a temporary alias to a column in the query result. It does not rename the actual database column.

SELECT Ename AS Name
FROM EMPLOYEE;

13.2 Calculated columns

SQL can calculate expressions in a query. For annual salary, multiply monthly Salary by 12:

SELECT Ename AS Name, Salary * 12
FROM EMPLOYEE;

SELECT Ename AS Name,
       Salary * 12 AS 'Annual Salary'
FROM EMPLOYEE;

If an alias contains a space, enclose it in quotes. The calculated Annual Salary is only in the output; it is not stored as a new column.

13.3 DISTINCT

By default, repeated values may appear in query results. DISTINCT returns only distinct values.

SELECT DISTINCT DeptId
FROM EMPLOYEE;

To find distinct salaries in department D01:

SELECT DISTINCT Salary
FROM EMPLOYEE
WHERE DeptId = 'D01';

14. WHERE Clause and Operators

WHERE retrieves only those rows that satisfy a condition.

OperatorMeaningExample
=Equal toDeptId = 'D01'
<Less thanSalary < 30000
<=Less than or equalSalary <= 30000
>Greater thanSalary > 50000
>=Greater than or equalSalary >= 50000
!=Not equal toDeptId != 'D01'

14.1 AND

Every condition connected by AND must be true.

SELECT *
FROM EMPLOYEE
WHERE Salary > 5000 AND DeptId = 'D04';

14.2 OR

At least one condition connected by OR must be true.

SELECT *
FROM EMPLOYEE
WHERE DeptId = 'D01' OR DeptId = 'D02';

14.3 NOT

NOT reverses a condition.

SELECT *
FROM EMPLOYEE
WHERE NOT Ename = 'Aaliya';

To find employees with salaries between 20,000 and 50,000 inclusive using comparison operators:

SELECT Ename, DeptId
FROM EMPLOYEE
WHERE Salary >= 20000 AND Salary <= 50000;
AND vs OR: AND requires all conditions to be true. OR requires at least one condition to be true.

15. BETWEEN, IN and NOT IN

15.1 BETWEEN

BETWEEN checks whether a value lies within a range. The lower and upper boundary values are included.

SELECT Ename, DeptId
FROM EMPLOYEE
WHERE Salary BETWEEN 20000 AND 50000;

Equivalent condition:

WHERE Salary >= 20000 AND Salary <= 50000

15.2 IN

IN compares a value with a list and returns rows where the value matches any item in the list.

SELECT *
FROM EMPLOYEE
WHERE DeptId IN ('D01', 'D02', 'D04');

This is shorter than joining the same comparisons with OR.

15.3 NOT IN

NOT IN excludes the values in the list.

SELECT *
FROM EMPLOYEE
WHERE DeptId NOT IN ('D01', 'D02');
OperatorUse
BETWEEN A AND BRange including A and B.
IN (A, B, C)Match any listed value.
NOT IN (A, B)Exclude listed values.

16. ORDER BY Clause

ORDER BY arranges query output according to one or more columns. Ascending order is the default.

16.1 Ascending

SELECT *
FROM EMPLOYEE
ORDER BY Salary;

-- Explicit ascending order
SELECT *
FROM EMPLOYEE
ORDER BY Salary ASC;

16.2 Descending

SELECT *
FROM EMPLOYEE
ORDER BY Salary DESC;

DESC means descending. Multiple sort columns may be supplied; the later column is used when earlier sort values tie.

SELECT *
FROM EMPLOYEE
ORDER BY Salary ASC, Bonus DESC;

17. Handling NULL Values

NULL represents missing, unknown or not-applicable information. It is not the same as zero or an empty string. Arithmetic involving NULL generally produces NULL because the result is unknown.

17.1 Find NULL values

SELECT *
FROM EMPLOYEE
WHERE Bonus IS NULL;

This finds employees who have not been assigned a bonus.

17.2 Find non-NULL values

SELECT Ename
FROM EMPLOYEE
WHERE Bonus IS NOT NULL;
Do not test NULL using Bonus = NULL. Use Bonus IS NULL or Bonus IS NOT NULL.

18. Substring Pattern Matching – LIKE

LIKE is used with WHERE when an exact match is not required and we want to search for a character pattern or substring.

WildcardMeaning
%Zero, one or multiple characters.
_Exactly one character.

18.1 Name starts with K

SELECT *
FROM EMPLOYEE
WHERE Ename LIKE 'K%';

18.2 Name ends with a

SELECT *
FROM EMPLOYEE
WHERE Ename LIKE '%a';

18.3 Exactly five characters, last four are ANYA

SELECT *
FROM EMPLOYEE
WHERE Ename LIKE '_ANYA';

_ matches one first character; ANYA matches the remaining four.

18.4 Name contains 'se'

SELECT Ename
FROM EMPLOYEE
WHERE Ename LIKE '%se%';

18.5 Second character is a

SELECT Ename
FROM EMPLOYEE
WHERE Ename LIKE '_a%';
PatternMeaning
'A%'Starts with A
'%A'Ends with A
'%A%'Contains A anywhere
'_A%'Second character is A
'A_'Exactly two characters, first is A
'__A%'Third character is A

19. Data Updation – UPDATE

UPDATE modifies existing values in one or more columns of selected records.

UPDATE table_name
SET column1 = value1,
    column2 = value2
WHERE condition;

19.1 Update one column in one row

Set GUID for student RollNumber 3:

UPDATE STUDENT
SET GUID = '101010101010'
WHERE RollNumber = 3;

19.2 Update multiple columns

UPDATE GUARDIAN
SET GAddress = 'WZ-68, Azad Avenue, Bijnour, MP',
    GPhone = '4817362092'
WHERE GUID = '466444444666';

19.3 Verify changes

SELECT * FROM GUARDIAN;
Critical caution: If WHERE is omitted, all rows may be updated. First run a SELECT with the intended condition to verify which rows will be affected.

20. Data Deletion – DELETE

DELETE removes one or more records from a table. It does not remove the table structure.

DELETE FROM table_name
WHERE condition;

Example: Delete the student whose RollNumber is 2:

DELETE FROM STUDENT
WHERE RollNumber = 2;

Verify the remaining records:

SELECT * FROM STUDENT;
Critical caution: If WHERE is omitted, all records in the table may be deleted, although the table itself remains. Never execute a DELETE without checking the intended condition.

21. Complete Chapter Summary and Quick Revision

Command / clausePurposeSyntax reminder
CREATE DATABASECreate a databaseCREATE DATABASE db;
USESelect a databaseUSE db;
SHOW TABLESList tables in active databaseSHOW TABLES;
CREATE TABLECreate table structureCREATE TABLE t (...);
DESCShow table structureDESC t;
ALTER TABLEChange table structureALTER TABLE t ADD ...;
DROPRemove table/databaseDROP TABLE t;
INSERTAdd recordsINSERT INTO t VALUES (...);
SELECTRetrieve dataSELECT * FROM t;
DISTINCTRemove repeated result valuesSELECT DISTINCT c FROM t;
WHEREFilter recordsSELECT * FROM t WHERE ...;
BETWEENInclusive range testc BETWEEN x AND y
INMatch a listc IN (x,y)
ORDER BYSort resultORDER BY c DESC
IS NULLFind missing valuesWHERE c IS NULL
LIKEPattern matchingWHERE c LIKE 'A%'
UPDATEModify recordsUPDATE t SET c=v WHERE ...;
DELETEDelete recordsDELETE FROM t WHERE ...;

Important differences

PairDifference
CHAR / VARCHARCHAR is fixed-length; VARCHAR is variable-length.
PRIMARY KEY / FOREIGN KEYPrimary key identifies a row in its own table; foreign key refers to a key in another table.
DESC / ORDER BY ... DESCDESC table describes table structure; DESC after ORDER BY sorts descending.
ALTER / UPDATEALTER changes table structure; UPDATE changes stored values.
DELETE / DROPDELETE removes rows; DROP removes a table or database object.
AND / ORAND requires all conditions true; OR requires at least one condition true.
BETWEEN / INBETWEEN checks a range; IN checks membership in a list.
% / _% matches zero or more characters; _ matches exactly one character.

Common errors to avoid

  • Forgetting the semicolon at the end of a statement.
  • Using = NULL instead of IS NULL.
  • Confusing DESC table description with descending sort.
  • Confusing ALTER (structure) with UPDATE (data).
  • Confusing DELETE (rows) with DROP (table/database).
  • Forgetting WHERE in UPDATE or DELETE.
  • Using double quotes inconsistently; use single quotes for text/date values in the textbook examples.
  • Inserting a child row before the referenced parent row exists.
  • Forgetting that BETWEEN includes both endpoints.
  • Mixing up % and _ wildcards.

22. Textbook Exercise – Coverage and Practice Guidance

The uploaded chapter ends with exercises covering the following skills. Use these as a checklist while practising:

  1. Match ALTER, UPDATE, DELETE, INSERT INTO, constraints, DESC and CREATE with their functions.
  2. Interpret a CREATE TABLE statement: determine degree, identify a column, understand case-insensitive SELECT and reason about INSERT/DELETE results.
  3. Identify the foreign key and explain what the asterisk (*) retrieves in SELECT.
  4. Write queries on a MOVIE table: retrieve all columns, select specific columns, list distinct categories, calculate NetProfit with an alias, apply salary/cost ranges, use IN and identify NULL release dates.
  5. Create a SPORTS database and TEAM table, define a primary key, describe the structure, insert records and display them.
  6. Create MATCH_DETAILS with suitable data types and constraints, then define foreign keys to TEAM.
  7. Write queries on match scores, compare first-team and second-team scores, and rename a relation and its attributes as required by the exercise.
  8. Design STUDENT_PROJECT with STUDENT, PROJECT_ASSIGNED and PROJECT tables; choose primary and foreign keys and query students by stream/guide teacher.
  9. Work with EMPLOYEE and DEPENDENT tables: retrieve employee/dependent names, filter by department, find employees with no dependents and count dependents by employee.
  10. Work with SCHOOL_UNIFORM, UNIFORM and PRICE: rename PRICE to COST, insert an item/price, define a foreign key, require a valid item name and apply a positive-price constraint.
These exercise prompts are retained as a coverage checklist; the notes above explain the SQL concepts and syntax needed to solve them. For actual practical work, create a fresh practice database and execute each statement in MySQL.
Class XI Informatics Practices (065) · Chapter 8 – Introduction to Structured Query Language (SQL)
Study notes prepared from the uploaded NCERT textbook chapter, including its examples, tables, syntax and end-of-chapter exercise topics.

TEXTBOOK SOLUTION

Step-by-step solved textbook exercises, derivations, and solutions.

Class XI IP – Chapter 8 SQL | Textbook Exercise Solutions

Chapter 8 – Introduction to Structured Query Language (SQL)

Class XI – Informatics Practices (065)

Complete Textbook Exercise Questions and Answers | MySQL

Q1. Match the following clauses with their respective functions.

SQL clause / commandCorrect function
ALTERChange the structure of a table or a column
UPDATEUpdate existing information in a table
DELETEDelete an existing row from a table
INSERT INTOInsert the values in a table
CONSTRAINTSRestrictions on columns
DESCDisplay the structure of a table
CREATECreate a database or table

Explanation: ALTER modifies table structure; UPDATE changes existing record values; DELETE removes records; INSERT INTO adds records; constraints restrict column values; DESC displays table structure; CREATE creates database objects.

Q2. Choose the appropriate answer with respect to the following code snippet.

CREATE TABLE student (
    name CHAR(30),
    student_id INT,
    gender CHAR(1),
    PRIMARY KEY (student_id)
);

(a) What will be the degree of student table?

Options: (i) 30   (ii) 1   (iii) 3   (iv) 4

Answer: (iii) 3
Degree means the total number of attributes (columns) in a table. The table has name, student_id and gender.

(b) What does name represent in the above code snippet?

Options: (i) A table   (ii) A row   (iii) A column   (iv) A database

Answer: (iii) A column
name is an attribute (column) of the student table.

(c) What is true about the following SQL statement?

SelecT * fROM student;

Options: (i) Displays contents of table student; (ii) Displays column names and contents; (iii) Error due to improper case; (iv) Displays only column names.

Answer: (ii) Displays column names and contents of table student.
SQL keywords are case-insensitive. The asterisk (*) retrieves all columns, and the result displays column names and records.

(d) What will be the output of the following query?

INSERT INTO student
VALUES ("Suhana",109,'F'),
       ("Rivaan",102,'M'),
       ("Atharv",103,'M'),
       ("Rishika",105,'F'),
       ("Garvit",104,'M'),
       ("Shaurya",109,'M');

Options: (i) Error   (ii) No Error   (iii) Depends on compiler   (iv) Successful completion

Answer: (i) Error
The statement has a duplicate primary-key value (student_id 109). A primary key must be unique. The multi-row INSERT syntax uses VALUES once, followed by comma-separated row groups.

Correct multi-row syntax (still fails because 109 is duplicated):

INSERT INTO student
VALUES
('Suhana', 109, 'F'),
('Rivaan', 102, 'M'),
('Atharv', 103, 'M'),
('Rishika', 105, 'F'),
('Garvit', 104, 'M'),
('Shaurya', 109, 'M');

(e) In the following query, how many rows will be deleted?

DELETE student
WHERE student_id = 109;

Options: (i) 1 row; (ii) All rows where student_id is 109; (iii) No row; (iv) 2 rows.

Answer: (iv) 2 rows
If two records with student_id 109 exist, both match the condition and are deleted. The clearer MySQL syntax is:
DELETE FROM student
WHERE student_id = 109;
Important clarification: This answer assumes two matching records exist. The INSERT statement in part (d) would fail because of the duplicate primary key, so it would not itself create those two records.

Q3. Fill in the blanks.

(a) __________ declares that an index in one table is related to that in another table.

Options: (i) Primary Key   (ii) Foreign Key   (iii) Composite Key   (iv) Secondary Key

Answer: (ii) Foreign Key
A foreign key is an attribute in one table that refers to a key in another table. It establishes a relationship between tables.

(b) The symbol Asterisk (*) in a SELECT query retrieves __________.

Options: (i) All data from the table   (ii) Data of primary key only   (iii) NULL data   (iv) None of the mentioned

Answer: (i) All data from the table
SELECT * FROM student;

This query retrieves all columns from the specified table.

Q4. Consider the following MOVIE database and answer the SQL queries based on it.

MovieIDMovieNameCategoryReleaseDateProductionCostBusinessCost
001Hindi_MovieMusical2018-04-23124500130000
002Tamil_MovieAction2016-05-17112000118000
003English_MovieHorror2017-08-06245000360000
004Bengali_MovieAdventure2017-01-0472000100000
005Telugu_MovieActionNULL100000NULL
006Punjabi_MovieComedyNULL30500NULL

(a) Retrieve movies information without mentioning their column names.

Answer:
SELECT *
FROM MOVIE;

SELECT * retrieves all columns and all records from MOVIE.

(b) List business done by the movies showing only MovieID, MovieName and BusinessCost.

Answer:
SELECT MovieID, MovieName, BusinessCost
FROM MOVIE;

(c) List the different categories of movies.

Answer:
SELECT DISTINCT Category
FROM MOVIE;

Expected output:

Category
Musical
Action
Horror
Adventure
Comedy

DISTINCT eliminates duplicate values from the result.

(d) Find the net profit of each movie showing its ID, Name and Net Profit.

Hint: Net Profit = BusinessCost − ProductionCost.

Answer:
SELECT
    MovieID,
    MovieName,
    BusinessCost - ProductionCost AS NetProfit
FROM MOVIE;

Expected output:

MovieIDMovieNameNetProfit
001Hindi_Movie5500
002Tamil_Movie6000
003English_Movie115000
004Bengali_Movie28000
005Telugu_MovieNULL
006Punjabi_MovieNULL

Is NetProfit a part of the MOVIE relation? No. It is a calculated/derived column created in the query output, not a permanent attribute of MOVIE.

What happens for a movie which has not yet released? The result is NULL, not zero, because BusinessCost is NULL and arithmetic involving NULL produces NULL.

(e) List all movies with ProductionCost greater than 80,000 and less than 1,25,000, showing ID, Name and ProductionCost.

Answer:
SELECT MovieID, MovieName, ProductionCost
FROM MOVIE
WHERE ProductionCost > 80000
AND ProductionCost < 125000;

Expected output:

MovieIDMovieNameProductionCost
001Hindi_Movie124500
002Tamil_Movie112000
005Telugu_Movie100000

AND requires both conditions to be true.

(f) List all movies which fall in the category of Comedy or Action.

Answer:
SELECT *
FROM MOVIE
WHERE Category = 'Comedy'
OR Category = 'Action';

Alternative using IN:

SELECT *
FROM MOVIE
WHERE Category IN ('Comedy', 'Action');

Matching movies: Tamil_Movie, Telugu_Movie and Punjabi_Movie.

(g) List the movies which have not been released yet.

Answer:
SELECT *
FROM MOVIE
WHERE ReleaseDate IS NULL;

IS NULL checks missing or unknown values. Do not use = NULL.

Q5. Create a Sports database for inter-class cricket matches.

The school wants to conduct cricket matches between Class XI and Class XII. Four teams are Team Titan, Team Rockers, Team Magnet and Team Hurricane.

(a) Create a database named Sports.

CREATE DATABASE Sports;
USE Sports;

(b) Create a table TEAM with the given considerations.

TeamID stores integer values from 1 to 9 and uniquely identifies a team. TeamName is a string of at least 10 characters.

CREATE TABLE TEAM
(
    TeamID INT,
    TeamName VARCHAR(30),
    CHECK (TeamID BETWEEN 1 AND 9),
    CHECK (CHAR_LENGTH(TeamName) >= 10)
);

(c) Using table-level constraint, make TeamID the primary key.

ALTER TABLE TEAM
ADD PRIMARY KEY (TeamID);

Alternatively, define PRIMARY KEY (TeamID) inside CREATE TABLE.

(d) Show the structure of TEAM.

DESC TEAM;

Alternative: DESCRIBE TEAM;

(e) Insert the four teams into TEAM.

INSERT INTO TEAM
VALUES
(1, 'Team Titan'),
(2, 'Team Rockers'),
(3, 'Team Magnet'),
(4, 'Team Hurricane');

(f) Show the contents of TEAM.

SELECT *
FROM TEAM;

Expected output:

TeamIDTeamName
1Team Titan
2Team Rockers
3Team Magnet
4Team Hurricane

(g) Create MATCH_DETAILS and insert the given data.

MatchIDMatchDateFirstTeamIDSecondTeamIDFirstTeamScoreSecondTeamScore
M12018-07-17129086
M22018-07-18344548
M32018-07-19137856
M42018-07-19245667
M52018-07-20143287
M62018-07-21236751
CREATE TABLE MATCH_DETAILS
(
    MatchID CHAR(2),
    MatchDate DATE,
    FirstTeamID INT,
    SecondTeamID INT,
    FirstTeamScore INT,
    SecondTeamScore INT,
    PRIMARY KEY (MatchID)
);
INSERT INTO MATCH_DETAILS
VALUES
('M1', '2018-07-17', 1, 2, 90, 86),
('M2', '2018-07-18', 3, 4, 45, 48),
('M3', '2018-07-19', 1, 3, 78, 56),
('M4', '2018-07-19', 2, 4, 56, 67),
('M5', '2018-07-20', 1, 4, 32, 87),
('M6', '2018-07-21', 2, 3, 67, 51);

(h) Add foreign keys referencing TEAM so that only existing teams can be recorded.

ALTER TABLE MATCH_DETAILS
ADD FOREIGN KEY (FirstTeamID)
REFERENCES TEAM(TeamID);

ALTER TABLE MATCH_DETAILS
ADD FOREIGN KEY (SecondTeamID)
REFERENCES TEAM(TeamID);

Both team ID columns refer to TEAM.TeamID. These constraints prevent references to team IDs that do not exist in TEAM.

Q6. Using the Sports database containing TEAM and MATCH_DETAILS, answer the following relational algebra queries.

Relations: TEAM(TeamID, TeamName) and MATCH_DETAILS(MatchID, MatchDate, FirstTeamID, SecondTeamID, FirstTeamScore, SecondTeamScore).

(a) Retrieve MatchID of matches where both teams scored greater than 70.

Relational Algebra:

\(\pi_{MatchID}(\sigma_{FirstTeamScore>70 \land SecondTeamScore>70}(MATCH\_DETAILS))\)

SQL:

SELECT MatchID
FROM MATCH_DETAILS
WHERE FirstTeamScore > 70
AND SecondTeamScore > 70;

Expected output: M1

(b) Retrieve MatchID where FirstTeam scored less than 70 but SecondTeam scored greater than 70.

Relational Algebra:

\(\pi_{MatchID}(\sigma_{FirstTeamScore<70 \land SecondTeamScore>70}(MATCH\_DETAILS))\)

SQL:

SELECT MatchID
FROM MATCH_DETAILS
WHERE FirstTeamScore < 70
AND SecondTeamScore > 70;

Expected output: M4, M5

(c) Find MatchID and date of matches played by Team 1 and won by it.

Relational Algebra:

\(\pi_{MatchID,MatchDate}(\sigma_{FirstTeamID=1 \land FirstTeamScore>SecondTeamScore}(MATCH\_DETAILS))\)

SQL:

SELECT MatchID, MatchDate
FROM MATCH_DETAILS
WHERE FirstTeamID = 1
AND FirstTeamScore > SecondTeamScore;

Expected output:

MatchIDMatchDate
M12018-07-17
M32018-07-19

(d) Find MatchID of matches played by Team 2 and not won by it.

SELECT MatchID
FROM MATCH_DETAILS
WHERE
(
    FirstTeamID = 2
    AND FirstTeamScore <= SecondTeamScore
)
OR
(
    SecondTeamID = 2
    AND SecondTeamScore <= FirstTeamScore
);

Correct expected output: M4

In M4, Team 2 scored 56 while Team 4 scored 67, so Team 2 did not win. In M6, Team 2 scored 67 while Team 3 scored 51, so Team 2 won and M6 must not be included.

(e) Rename TEAM to T_DATA and rename TeamID and TeamName to T_ID and T_NAME.

RENAME TABLE TEAM TO T_DATA;

ALTER TABLE T_DATA
RENAME COLUMN TeamID TO T_ID;

ALTER TABLE T_DATA
RENAME COLUMN TeamName TO T_NAME;

RENAME TABLE changes the table name. ALTER TABLE ... RENAME COLUMN changes column names.

Q7. Differentiate between the following commands.

(a) ALTER and UPDATE

ALTERUPDATE
ALTER is a DDL command.UPDATE is a DML command.
It changes the structure of a table.It changes existing records in a table.
It can add, remove or modify columns.It modifies values stored in columns.
It does not directly update record values.It does not change the table structure.

ALTER example:

ALTER TABLE STUDENT
ADD Email VARCHAR(50);

This adds a new column named Email.

UPDATE example:

UPDATE STUDENT
SET Email = 'student@gmail.com'
WHERE RollNo = 101;

This updates the Email value for the student whose RollNo is 101.

(b) DELETE and DROP

DELETEDROP
DELETE is a DML command.DROP is a DDL command.
It removes records from a table.It removes an entire database object, such as a table or database.
It can delete selected records using WHERE.It removes the complete specified table or database.
Table structure remains after deletion.The dropped table structure is also removed.

DELETE example:

DELETE FROM STUDENT
WHERE RollNo = 101;

DROP example:

DROP TABLE STUDENT;

DELETE removes matching records; DROP removes the table structure and its records.

Q8. Create a database called STUDENT_PROJECT having the following tables. Choose appropriate data types and apply necessary constraints.

Required table structures

STUDENT: RollNo, Name, Stream, Section, RegistrationID

Stream values: Science, Commerce or Humanities. Section values: I or II.

PROJECT_ASSIGNED: RegistrationID, ProjectID, AssignDate

PROJECT: ProjectID, ProjectName, SubmissionDate, TeamSize, GuideTeacher

Create and select the database.

CREATE DATABASE STUDENT_PROJECT;
USE STUDENT_PROJECT;

Create STUDENT.

CREATE TABLE STUDENT
(
    RollNo INT,
    Name VARCHAR(40) NOT NULL,
    Stream VARCHAR(15),
    Section CHAR(1),
    RegistrationID INT,
    PRIMARY KEY (RegistrationID),
    UNIQUE (RollNo),
    CHECK (Stream IN ('Science', 'Commerce', 'Humanities')),
    CHECK (Section IN ('I', 'II'))
);

Create PROJECT.

CREATE TABLE PROJECT
(
    ProjectID INT,
    ProjectName VARCHAR(50) NOT NULL,
    SubmissionDate DATE,
    TeamSize INT,
    GuideTeacher VARCHAR(40),
    PRIMARY KEY (ProjectID),
    CHECK (TeamSize > 0)
);

Create PROJECT_ASSIGNED.

CREATE TABLE PROJECT_ASSIGNED
(
    RegistrationID INT,
    ProjectID INT,
    AssignDate DATE,
    PRIMARY KEY (RegistrationID, ProjectID),
    FOREIGN KEY (RegistrationID)
        REFERENCES STUDENT(RegistrationID),
    FOREIGN KEY (ProjectID)
        REFERENCES PROJECT(ProjectID)
);

(a) Populate these tables with appropriate data.

Insert into STUDENT:

INSERT INTO STUDENT
VALUES
(1, 'Aarav', 'Science', 'I', 1001),
(2, 'Diya', 'Commerce', 'II', 1002),
(3, 'Rohan', 'Humanities', 'I', 1003),
(4, 'Meera', 'Commerce', 'I', 1004),
(5, 'Kabir', 'Science', 'II', 1005);

Insert into PROJECT:

INSERT INTO PROJECT
VALUES
(101, 'Library Management', '2026-12-10', 3, 'Mr Sharma'),
(102, 'Sales Analysis', '2026-12-15', 4, 'Ms Patel'),
(103, 'Website Development', '2026-12-20', 3, 'Mr Sharma');

Insert into PROJECT_ASSIGNED:

INSERT INTO PROJECT_ASSIGNED
VALUES
(1001, 101, '2026-11-01'),
(1002, 102, '2026-11-02'),
(1003, 103, '2026-11-03'),
(1004, 102, '2026-11-04'),
(1005, 101, '2026-11-05');

(b) Write SQL queries for the following.

The remaining sub-questions are answered below.

(c) Find the names of students in Science Stream.

SELECT Name
FROM STUDENT
WHERE Stream = 'Science';

Expected output: Aarav, Kabir.

(d) What will be the primary keys of the three tables?

TablePrimary key
STUDENTRegistrationID
PROJECT_ASSIGNEDRegistrationID, ProjectID (composite primary key)
PROJECTProjectID

(e) What are the foreign keys of the three relations?

TableForeign keyReferences
STUDENTNone—
PROJECTNone—
PROJECT_ASSIGNEDRegistrationIDSTUDENT(RegistrationID)
PROJECT_ASSIGNEDProjectIDPROJECT(ProjectID)

(f) Find names of all students studying in Commerce stream and guided by the same teacher, even if assigned different projects.

SELECT DISTINCT S.Name, P.GuideTeacher
FROM STUDENT S
JOIN PROJECT_ASSIGNED PA
    ON S.RegistrationID = PA.RegistrationID
JOIN PROJECT P
    ON PA.ProjectID = P.ProjectID
WHERE S.Stream = 'Commerce';

Expected output for the sample records:

NameGuideTeacher
DiyaMs Patel
MeeraMs Patel

Join STUDENT with PROJECT_ASSIGNED using RegistrationID, then join PROJECT using ProjectID. Filter Commerce students and display their names and guide teachers.

Q9. An organization ABC maintains a database EMP-DEPENDENT to record employee and dependent details.

EMPLOYEE: EMPLOYEE(AadhaarNo, Name, Address, Department, EmpID)

DEPENDENT: DEPENDENT(EmpID, DependentName, Relationship)

Assumption: EmpID uniquely identifies an employee and is the primary key in EMPLOYEE. It is a foreign key in DEPENDENT.

Create the database and select it.

CREATE DATABASE EMP_DEPENDENT;
USE EMP_DEPENDENT;

Create EMPLOYEE.

CREATE TABLE EMPLOYEE
(
    AadhaarNo CHAR(12),
    Name VARCHAR(40),
    Address VARCHAR(100),
    Department VARCHAR(30),
    EmpID INT,
    PRIMARY KEY (EmpID)
);

Create DEPENDENT.

CREATE TABLE DEPENDENT
(
    EmpID INT,
    DependentName VARCHAR(40),
    Relationship VARCHAR(20),
    FOREIGN KEY (EmpID)
        REFERENCES EMPLOYEE(EmpID)
);

(a) Find the names of employees with their dependent names.

SELECT E.Name, D.DependentName
FROM EMPLOYEE E
INNER JOIN DEPENDENT D
    ON E.EmpID = D.EmpID;

INNER JOIN returns employees who have matching records in DEPENDENT.

(b) Find employee details working in a department, say, PRODUCTION.

SELECT *
FROM EMPLOYEE
WHERE Department = 'PRODUCTION';

(c) Find employee names having no dependent.

SELECT E.Name
FROM EMPLOYEE E
LEFT JOIN DEPENDENT D
    ON E.EmpID = D.EmpID
WHERE D.EmpID IS NULL;

LEFT JOIN keeps all employees. Where no dependent matches, dependent-side columns are NULL. IS NULL identifies those employees.

(d) Find names of employees working in SALES and having exactly two dependents.

SELECT E.Name
FROM EMPLOYEE E
INNER JOIN DEPENDENT D
    ON E.EmpID = D.EmpID
WHERE E.Department = 'SALES'
GROUP BY E.EmpID, E.Name
HAVING COUNT(D.DependentName) = 2;

WHERE filters SALES employees, GROUP BY groups their dependent records, COUNT counts dependents and HAVING selects employees with exactly two.

Q10. Wonderful Garments maintains SCHOOL_UNIFORM containing UNIFORM and PRICE relations.

UNIFORM

UCodeUNameUColor
1ShirtWhite
2PantGrey
3SkirtGrey
4TieBlue
5SocksBlue
6BeltBlue

PRICE

UCodeSizePrice
1M500
1L580
1XL620
2M810
2L890
2XL940
3M770
3L830
3XL910
4S150
4L170
5S180
5L210
6M110
6L140
6XL160

(a) Change the name of relation PRICE to COST.

RENAME TABLE PRICE TO COST;

(b) Insert a red, medium-size handkerchief priced at 100 each into COST.

Assume the new item is assigned UCode 7.

INSERT INTO COST
VALUES (7, 'M', 100);

(c) Allow data in COST only if the UCode already exists in UNIFORM.

ALTER TABLE COST
ADD CONSTRAINT FK_COST_UNIFORM
FOREIGN KEY (UCode)
REFERENCES UNIFORM(UCode);

Insert the handkerchief's details in UNIFORM first, then its price in COST:

INSERT INTO UNIFORM
VALUES (7, 'Handkerchief', 'Red');

INSERT INTO COST
VALUES (7, 'M', 100);

The foreign key ensures that COST.UCode must refer to an existing UNIFORM.UCode.

(d) Ensure that a new UCode can be assigned only if it has a valid UName.

ALTER TABLE UNIFORM
MODIFY UName VARCHAR(30) NOT NULL;

NOT NULL prevents a uniform record from being inserted without a name.

(e) Add a constraint that the price of an item is always greater than zero.

ALTER TABLE COST
ADD CONSTRAINT CHECK_PRICE
CHECK (Price > 0);

CHECK (Price > 0) ensures that the price must be greater than zero.

Important SQL commands covered in this exercise

CommandPurposeExample
CREATE DATABASECreate a databaseCREATE DATABASE School;
USESelect a databaseUSE School;
CREATE TABLECreate a tableCREATE TABLE Student (...);
DESCDisplay table structureDESC Student;
INSERT INTOInsert recordsINSERT INTO Student VALUES (...);
SELECTRetrieve recordsSELECT * FROM Student;
DISTINCTRemove duplicate valuesSELECT DISTINCT City FROM Student;
WHEREApply conditionsWHERE Marks > 80;
UPDATEModify existing recordsUPDATE Student SET Marks=90 WHERE RollNo=1;
DELETEDelete recordsDELETE FROM Student WHERE RollNo=1;
ALTER TABLEModify table structureALTER TABLE Student ADD Email VARCHAR(50);
RENAME TABLERename a tableRENAME TABLE PRICE TO COST;
DROP TABLERemove a tableDROP TABLE Student;

Important concepts to revise before the examination

  1. Difference between DDL and DML.
  2. Difference between DELETE, DROP and ALTER.
  3. Difference between primary key and foreign key.
  4. Difference between WHERE and HAVING.
  5. Use of DISTINCT, LIKE, BETWEEN and IN.
  6. Use of IS NULL and IS NOT NULL.
  7. Use of GROUP BY and aggregate functions.
  8. Use of INNER JOIN and LEFT JOIN.
  9. Composite primary keys.
  10. CHECK, UNIQUE, DEFAULT and NOT NULL constraints.
Study note: Sample records in Q8 are illustrative because the textbook asks students to populate the tables with appropriate data. SQL syntax and supported constraint behaviour can vary by MySQL version. Verify CHECK constraint enforcement on the MySQL version used in your lab.

MCQ

High-yield board questions, previous year questions (PYQs), and model answer keys.

Class XI IP Chapter 8 SQL – 50 MCQs

Class XI Informatics Practices – Chapter 8: SQL

50 Multiple-Choice Questions with answers and explanations

Practice Test – 50 MCQs

Select one option for each question. Click Check Answers to view your score and explanations. You can also reveal or hide all solutions.

Not checked yet

Q1. SQL stands for:

Correct answer: A. Structured Query Language

SQL is the standard language used to define, manipulate and retrieve data in relational databases.

Q2. Which prompt indicates that MySQL is ready to accept a statement?

Correct answer: A. mysql>

The MySQL shell displays the mysql> prompt when ready.

Q3. Which symbol normally terminates a complete SQL statement?

Correct answer: B. ;

A semicolon marks the end of a complete SQL statement.

Q4. SQL statements are generally:

Correct answer: B. Case-insensitive

The chapter explains that SQL keywords are not case-sensitive.

Q5. Which data type is fixed-length character data?

Correct answer: B. CHAR

CHAR(n) reserves a fixed character length.

Q6. Which data type is variable-length character data?

Correct answer: C. VARCHAR

VARCHAR(n) stores variable-length strings up to the declared maximum.

Q7. Which data type is suitable for a date in YYYY-MM-DD format?

Correct answer: A. DATE

The chapter uses DATE for calendar dates in YYYY-MM-DD format.

Q8. According to the chapter, INT occupies:

Correct answer: C. 4 bytes

The textbook specifies INT as a 4-byte integer.

Q9. Which constraint prevents NULL values in a column?

Correct answer: B. NOT NULL

NOT NULL requires a value for that column.

Q10. Which constraint uniquely identifies each row?

Correct answer: A. PRIMARY KEY

A primary key uniquely identifies each record and cannot be NULL.

Q11. A column that refers to a primary key in another table is called:

Correct answer: B. Foreign key

A foreign key creates a relationship by referencing a key in another table.

Q12. Which pair of constraints together can form a primary-key-like uniqueness and non-null rule?

Correct answer: B. NOT NULL and UNIQUE

A primary key combines uniqueness and non-null requirements.

Q13. Which command creates a database?

Correct answer: B. CREATE DATABASE

CREATE DATABASE database_name; creates a database.

Q14. Which command selects the active database?

Correct answer: B. USE

USE database_name; selects the database for subsequent operations.

Q15. Which command creates a table?

Correct answer: A. CREATE TABLE

CREATE TABLE defines the table structure and columns.

Q16. The degree of a relation means:

Correct answer: B. Number of columns

Degree is the number of attributes (columns) in a relation.

Q17. Which command displays the structure of a table?

Correct answer: B. DESC

DESC is the short form of DESCRIBE.

Q18. Which command changes the structure of an existing table?

Correct answer: A. ALTER TABLE

ALTER TABLE can add, drop or modify columns and constraints.

Q19. Which command permanently removes a table?

Correct answer: B. DROP TABLE

DROP TABLE removes the table definition and its data.

Q20. Which statement inserts a new row?

Correct answer: A. INSERT INTO

INSERT INTO adds records to a table.

Q21. When column names are omitted from INSERT, values must be supplied for:

Correct answer: B. All columns in table order

Without a column list, provide a value for every column in the table's defined order.

Q22. Which symbol/value represents a missing or unknown value in SQL?

Correct answer: C. NULL

NULL represents missing, unknown or not-applicable data.

Q23. Which statement retrieves data from a table?

Correct answer: A. SELECT

SELECT is the SQL query statement.

Q24. What does SELECT * retrieve?

Correct answer: B. All columns

The asterisk requests all attributes/columns from the selected table.

Q25. Which clause specifies the source table?

Correct answer: B. FROM

FROM names the table from which data is retrieved.

Q26. Which clause filters rows according to a condition?

Correct answer: A. WHERE

WHERE restricts the result to rows satisfying the condition.

Q27. Which keyword removes duplicate values from a query result?

Correct answer: B. DISTINCT

DISTINCT displays non-repeated result values.

Q28. Which operator checks whether a value lies within an inclusive range?

Correct answer: B. BETWEEN

BETWEEN includes both its lower and upper boundary values.

Q29. Which operator checks membership in a list of values?

Correct answer: A. IN

IN returns true when the tested value matches any value in the list.

Q30. Which clause sorts the query result?

Correct answer: B. ORDER BY

ORDER BY arranges rows by one or more specified columns.

Q31. What is the default sorting order of ORDER BY?

Correct answer: B. Ascending

Ascending order is the default unless DESC is specified.

Q32. Which condition correctly finds rows where Bonus is missing?

Correct answer: B. Bonus IS NULL

NULL must be tested with IS NULL, not the equality operator.

Q33. Which condition finds rows where Bonus has a value?

Correct answer: A. Bonus IS NOT NULL

IS NOT NULL selects rows with a non-NULL value.

Q34. Which LIKE wildcard represents zero or more characters?

Correct answer: B. %

% can represent zero, one or multiple characters.

Q35. Which LIKE wildcard represents exactly one character?

Correct answer: B. _

Underscore represents a single character.

Q36. What does LIKE 'K%' match?

Correct answer: B. Names starting with K

K followed by % means K at the beginning and any number of characters after it.

Q37. What does LIKE '%a' match?

Correct answer: B. Values ending with a

The percent wildcard before a allows any preceding characters; a is the final character.

Q38. Which logical operator requires both conditions to be true?

Correct answer: B. AND

AND combines conditions that must all be satisfied.

Q39. Which logical operator requires at least one condition to be true?

Correct answer: B. OR

OR is true when one or more conditions are true.

Q40. Which command modifies existing records?

Correct answer: A. UPDATE

UPDATE changes values in existing rows.

Q41. Which clause identifies the row(s) to modify in UPDATE?

Correct answer: B. WHERE

WHERE identifies the record(s) to update. Without it, all rows are affected.

Q42. Which command removes selected records but keeps the table structure?

Correct answer: B. DELETE

DELETE removes rows while retaining the table.

Q43. What happens if DELETE is executed without a WHERE clause?

Correct answer: B. All rows are deleted

Without WHERE, DELETE applies to every row in the table.

Q44. What happens if UPDATE is executed without a WHERE clause?

Correct answer: B. All rows are updated

Without WHERE, every row is subject to the SET operation.

Q45. Which command adds a new column named income to GUARDIAN?

Correct answer: A. ALTER TABLE GUARDIAN ADD income INT;

ALTER TABLE ... ADD adds an attribute to an existing table.

Q46. Which statement adds a foreign key to STUDENT referring to GUARDIAN?

Correct answer: A. ALTER TABLE STUDENT ADD FOREIGN KEY(GUID) REFERENCES GUARDIAN(GUID);

The referenced table and its primary key must already exist and data types/sizes must match.

Q47. Which is the correct composite primary key syntax?

Correct answer: A. PRIMARY KEY (AttendanceDate, RollNumber)

A table-level PRIMARY KEY can list multiple columns inside parentheses.

Q48. Which is the correct difference between ALTER and UPDATE?

Correct answer: B. ALTER changes structure; UPDATE changes row values

ALTER is a DDL operation; UPDATE is a DML operation.

Q49. Which is the correct difference between DELETE and DROP?

Correct answer: A. DELETE removes rows; DROP removes a table/database structure

DELETE removes records; DROP removes the database object itself.

Q50. If a foreign key in a child table refers to a parent table, which should normally be populated first?

Correct answer: B. Parent/referenced table

The referenced record must exist before inserting a child row that references it.

Class XI Informatics Practices • Chapter 8 SQL • 50 MCQs