IT Practicals Skill Set 4 (PostgreSQL DBMS Queries) Class 11 IT SOP 4 Solutions | FYJC माहिती तंत्रज्ञान

IT Practicals Skill Set 4 (PostgreSQL DBMS Queries) Class 11 IT SOP 4 Solutions (इयत्ता ११ वी माहिती तंत्रज्ञान प्रात्यक्षिक – PostgreSQL DBMS Queries SOP 4) — Complete Maharashtra State Board (MSBSHSE) Balbharati practical solutions for FYJC Science, Commerce, and Arts streams, covering the PostgreSQL Concept Overview, verified Balbharati DBMS SQL practicals (Hospital, School-Master, and Employee-Salary relationships) with clean SQL queries, terminal execution steps, SOP output, objective tables, short answers, मराठी टीप, and Exam FAQs.

📚 Class 11 IT (FYJC Sci/Comm/Arts): ← Prev: SOP 3 • All 10 Units Index • Class 11 Hub • Next: SOP 5 →

1. Concept Overview – PostgreSQL DBMS Queries for Class 11 IT SOP 4

In the MSBSHSE Balbharati Class 11 Information Technology practical curriculum, PostgreSQL serves as the open-source Relational Database Management System (RDBMS) for creating databases, defining tables with data types and keys, inserting records, and querying relationships. (Note: In the printed Balbharati practical manual, PostgreSQL DBMS assignments appear under Skill Set 6: DBMS as SOP 1, SOP 2, and SOP 3.) Review these essential PostgreSQL commands, data types, and SQL clauses before performing your lab practicals:

Command / Concept Category Syntax & Practical Exam Usage
psql (SQL Shell) CLI Interface Interactive terminal client used to connect to PostgreSQL (via sudo -i -u postgres and psql on Linux, or SQL Shell on Windows).
CREATE DATABASE DDL Command Creates a new database in PostgreSQL (e.g., CREATE DATABASE hospital;). Every SQL statement ends with a semicolon (;).
\c (Connect) Meta-Command Connects or switches to a specific database in psql (e.g., \c school_master;).
\l & \dt Meta-Commands \l lists all databases on the server; \dt lists all tables inside the currently connected database.
\d tablename Meta-Command Displays the column names, data types, and constraints (schema) of a table (e.g., \d patients).
\q (Quit) Meta-Command Safely exits the psql interactive command shell and returns to the OS terminal.
CREATE TABLE DDL Command Defines a new relational table along with column names, data types, and key constraints.
PostgreSQL Data Types Column Types INT (whole numbers), BIGINT (10-digit phone numbers), VARCHAR(n) / TEXT (strings), DATE (YYYY-MM-DD), NUMERIC (currency/salary).
PRIMARY KEY Constraint Uniquely identifies each row in a table; automatically enforces uniqueness and prevents NULL values.
FOREIGN KEY Referential Constraint Links a column in a child table to a PRIMARY KEY in a parent table using REFERENCES to build relationships.
INSERT INTO DML Command Adds new rows (records) into an existing table with values matching each column’s data type.
SELECT, UPDATE, DELETE DML Commands SELECT retrieves records (with optional WHERE and ORDER BY); UPDATE modifies existing rows; DELETE removes rows.

2. Official Balbharati PostgreSQL DBMS Practicals (SOP 4 / Skill Set 6) – SQL Queries & Output

Below are the complete, verified Balbharati Class 11 IT PostgreSQL practical assignments covering database creation, table design, multi-record insertion, relational keys, and query execution.

A. PostgreSQL Practical SOP 1: Hospital Database & Patients Table

Official Balbharati Problem Statement: Create a database using PostgreSQL named hospital. In this database, create a table of patients with the fields: Patient_ID, Patient_name, Address, Room_number, and Doctor_name. Give appropriate data types for each field.

PostgreSQL SQL Queries (SOP 1)

-- Step 1: Create the hospital database
CREATE DATABASE hospital;

-- Step 2: Connect to the hospital database
\c hospital;

-- Step 3: Create the patients table with appropriate data types
CREATE TABLE patients (
    Patient_ID INT PRIMARY KEY,
    Patient_name VARCHAR(60) NOT NULL,
    Address TEXT,
    Room_number INT,
    Doctor_name VARCHAR(60)
);

-- Step 4: Inspect the table structure and view records
\d patients;
SELECT * FROM patients;

Sample Insert & Verification Query (Optional Practice):

INSERT INTO patients VALUES
(101, 'Ramesh Kulkarni', 'Kothrud, Pune', 204, 'Dr. Deshmukh'),
(102, 'Sneha Joshi', 'Dadar, Mumbai', 108, 'Dr. Patil');

SELECT Patient_ID, Patient_name, Room_number, Doctor_name FROM patients;

Expected SOP Terminal Output:

CREATE DATABASE
You are now connected to database "hospital" as user "postgres".
CREATE TABLE

 patient_id |  patient_name   | room_number |  doctor_name
------------+-----------------+-------------+--------------
        101 | Ramesh Kulkarni |         204 | Dr. Deshmukh
        102 | Sneha Joshi     |         108 | Dr. Patil
(2 rows)

B. PostgreSQL Practical SOP 2: School-Master Database & Students Table (5 Records)

Official Balbharati Problem Statement: Create a database using PostgreSQL named school_master. In this database, create a table of students with the fields: student_ID, student_name, Address, Phone_number, and Date_of_Birth. Assign appropriate data types and enter at least 5 records.

PostgreSQL SQL Queries (SOP 2)

-- Step 1: Create and connect to school_master database
CREATE DATABASE school_master;
\c school_master;

-- Step 2: Create the students table
CREATE TABLE students (
    student_ID INT PRIMARY KEY,
    student_name VARCHAR(50) NOT NULL,
    Address VARCHAR(100),
    Phone_number BIGINT,
    Date_of_Birth DATE
);

-- Step 3: Insert at least 5 student records
INSERT INTO students VALUES (1, 'Aarav Sharma', 'Mumbai', 9876543210, '2008-05-14');
INSERT INTO students VALUES (2, 'Rutuja Patil', 'Pune', 9123456789, '2008-08-22');
INSERT INTO students VALUES (3, 'Amit Deshmukh', 'Nagpur', 9988776655, '2007-12-05');
INSERT INTO students VALUES (4, 'Priya Kulkarni', 'Nashik', 9811223344, '2008-01-19');
INSERT INTO students VALUES (5, 'Rahul Verma', 'Thane', 9700112233, '2007-11-30');

-- Step 4: Display all 5 inserted records
SELECT * FROM students;

Additional Practice Queries (WHERE, ORDER BY, UPDATE):

-- Filter students living in Pune
SELECT student_ID, student_name, Phone_number FROM students WHERE Address = 'Pune';

-- Sort students alphabetically by name
SELECT * FROM students ORDER BY student_name ASC;

-- Update address for student_ID 5
UPDATE students SET Address = 'Navi Mumbai' WHERE student_ID = 5;

Expected SOP Terminal Output (SELECT * FROM students;):

 student_id |  student_name  | address | phone_number | date_of_birth
------------+----------------+---------+--------------+---------------
          1 | Aarav Sharma   | Mumbai  |   9876543210 | 2008-05-14
          2 | Rutuja Patil   | Pune    |   9123456789 | 2008-08-22
          3 | Amit Deshmukh  | Nagpur  |   9988776655 | 2007-12-05
          4 | Priya Kulkarni | Nashik  |   9811223344 | 2008-01-19
          5 | Rahul Verma    | Thane   |   9700112233 | 2007-11-30
(5 rows)

C. PostgreSQL Practical SOP 3: Employee & Salary Tables Relationship

Official Balbharati Problem Statement: Given the fields EmpId, EmpName, EmpDepartment (in the Employee table) and SalaryId, SalaryAmount, Bonus (in the Salary table), create both tables in PostgreSQL and establish a relationship between them.

PostgreSQL SQL Queries (SOP 3)

-- Step 1: Create and connect to a company database
CREATE DATABASE company_db;
\c company_db;

-- Step 2: Create the parent Employee table with Primary Key
CREATE TABLE employee (
    EmpId INT PRIMARY KEY,
    EmpName VARCHAR(60) NOT NULL,
    EmpDepartment VARCHAR(40)
);

-- Step 3: Create the child Salary table with Foreign Key referencing Employee(EmpId)
CREATE TABLE salary (
    SalaryId INT PRIMARY KEY,
    EmpId INT REFERENCES employee(EmpId),
    SalaryAmount NUMERIC(10, 2),
    Bonus NUMERIC(10, 2)
);

-- Step 4: Insert matching records into both tables
INSERT INTO employee VALUES
(101, 'Tanmay Joshi', 'IT'),
(102, 'Meera Sawant', 'Accounts'),
(103, 'Karan Shinde', 'HR');

INSERT INTO salary VALUES
(1, 101, 55000.00, 5000.00),
(2, 102, 48000.00, 4000.00),
(3, 103, 45000.00, 3500.00);

-- Step 5: Query combined data using INNER JOIN
SELECT e.EmpId, e.EmpName, e.EmpDepartment, s.SalaryAmount, s.Bonus
FROM employee e
INNER JOIN salary s ON e.EmpId = s.EmpId;

Expected SOP Terminal Output:

 empid |   empname    | empdepartment | salaryamount |  bonus
-------+--------------+---------------+--------------+---------
   101 | Tanmay Joshi | IT            |     55000.00 | 5000.00
   102 | Meera Sawant | Accounts      |     48000.00 | 4000.00
   103 | Karan Shinde | HR            |     45000.00 | 3500.00
(3 rows)

D. Step-by-Step Practical Execution Procedure (Terminal & pgAdmin Steps)

  1. Launch PostgreSQL Shell: On Ubuntu/Linux, open Terminal and run sudo -i -u postgres followed by psql. On Windows, open SQL Shell (psql) from the Start menu and press Enter for default host, database, port, and username, then enter your password.
  2. Create & Connect to Database: Execute CREATE DATABASE dbname; (ending with a semicolon) and switch into it using \c dbname;.
  3. Define Table Schema: Write the CREATE TABLE statement with accurate column names, data types (INT, BIGINT, VARCHAR, TEXT, DATE, NUMERIC), and PRIMARY KEY / REFERENCES constraints.
  4. Insert & Query Data: Use INSERT INTO to add records (enclosing text and date literals inside single quotes '...'), verify schema with \d tablename, and display data with SELECT * FROM tablename;.
  5. GUI Alternative (pgAdmin): You can also open pgAdmin, expand Servers → Databases, right-click to create a database, open the Query Tool, paste your SQL script, and click Execute (F5) to view tabular output.

3. Practical Viva & Objective Exam Practice – Class 11 IT SOP 4

MSBSHSE Class 11 IT practical examinations and online unit tests evaluate SQL syntax, PostgreSQL meta-commands, data types, and relational key rules through objective questions and viva voce.

A. Fill in the Blanks (PostgreSQL & SQL Practice)

No. Question Statement Correct Answer
1 In PostgreSQL psql, the ________ meta-command is used to connect or switch to a specific database. \c (e.g., \c hospital;)
2 The ________ SQL command is used to create a new table inside an active database. CREATE TABLE
3 To store a 10-digit Indian mobile number without integer overflow, the ________ numeric data type is preferred over INT. BIGINT (or NUMERIC / VARCHAR(15))
4 In PostgreSQL, date values in INSERT statements are enclosed in single quotes using the standard ________ format. YYYY-MM-DD
5 A ________ key constraint establishes a relational link between two tables by referencing the parent table’s Primary Key. Foreign Key (REFERENCES)
6 The ________ meta-command displays the structure (columns and data types) of a table in psql. \d tablename

B. State Whether the Following Statements Are True or False

No. Statement Answer & Reason
1 Every SQL statement in PostgreSQL should be terminated with a semicolon (;). True. The semicolon signals the end of an SQL query so psql executes it immediately.
2 The \l meta-command in psql deletes all databases from the PostgreSQL server. False. \l lists all available databases on the PostgreSQL server safely without deleting anything.
3 A Primary Key column in a table can store duplicate values or NULL entries. False. A Primary Key must contain unique, non-null values for every record.
4 In PostgreSQL, text literals and dates inside INSERT INTO must be enclosed in single quotes ('...'). True. Standard SQL requires single quotes for string and date constants, whereas numeric constants are unquoted.
5 A Foreign Key in a child table can link to a Primary Key in a parent table using the REFERENCES keyword. True. For example, EmpId INT REFERENCES employee(EmpId) links salary to employee.

C. Multiple Choice Questions (MCQ1, MCQ2 & MCQ3)

Type Question & Options Correct Option(s) & Explanation
MCQ1 Which psql meta-command lists all tables in the currently selected PostgreSQL database?
(A) \l   (B) \dt   (C) \q   (D) \c
(B) \dt
\dt displays all tables in the connected database, whereas \l lists databases and \q exits psql.
MCQ1 Which SQL clause filters rows returned by a SELECT query based on a condition?
(A) ORDER BY   (B) WHERE   (C) VALUES   (D) REFERENCES
(B) WHERE
The WHERE clause restricts output rows to records matching the specified condition.
MCQ1 Which data type is most appropriate for storing Date_of_Birth in the students table?
(A) INT   (B) BOOLEAN   (C) DATE   (D) BIGINT
(C) DATE
The DATE type validates and stores calendar dates in YYYY-MM-DD format.
MCQ2 Which two SQL commands belong to Data Manipulation Language (DML)?
(A) CREATE TABLE   (B) INSERT INTO   (C) SELECT   (D) DROP TABLE
(B) INSERT INTO and (C) SELECT
INSERT and SELECT manipulate/retrieve table data, whereas CREATE and DROP are DDL commands.
MCQ2 Which two PostgreSQL constraints establish and enforce a relationship between employee and salary tables?
(A) PRIMARY KEY   (B) ORDER BY   (C) FOREIGN KEY / REFERENCES   (D) DISTINCT
(A) PRIMARY KEY and (C) FOREIGN KEY / REFERENCES
A Foreign Key in the child table references the Primary Key of the parent table.
MCQ3 Which three statements are true about PostgreSQL practicals in Class 11 IT?
(A) \q exits the psql shell   (B) BIGINT stores 10-digit phone numbers   (C) SELECT * displays all columns   (D) SQL queries do not need semicolons   (E) \c creates a table
(A), (B), and (C)
\q quits psql, BIGINT handles 10-digit numbers cleanly, and SELECT * fetches every column.

D. Match the Following (PostgreSQL Commands & Purpose)

Column A (Command / Term) Column B (Purpose in PostgreSQL)
1. CREATE DATABASE Creates a new database on the PostgreSQL server
2. \c hospital; Connects the psql shell to the hospital database
3. \d patients Displays column names, data types, and keys of patients
4. INSERT INTO Adds new records (rows) into a database table
5. SELECT * FROM Retrieves and displays all rows and columns of a table
6. REFERENCES Links a Foreign Key column to a parent Primary Key

E. Answer the Following Questions in Brief (Viva & Exam Answers)

1. What is the difference between \l, \c, \dt, and \d in PostgreSQL?

  • \l: Lists all databases available on the PostgreSQL server.
  • \c dbname: Connects or switches the current session to the named database.
  • \dt: Lists all user-created tables inside the currently connected database.
  • \d tablename: Shows the complete schema (column names, data types, and constraints) of a specific table.

2. Why is BIGINT or VARCHAR used instead of INT for Phone_number in the students table?

  • A standard 32-bit INT data type has a maximum limit of 2,147,483,647, which cannot store 10-digit Indian mobile numbers starting with 7, 8, or 9.
  • Using BIGINT (64-bit integer) or VARCHAR(15) stores 10-digit phone numbers accurately without out-of-range errors.

3. How do you establish a relationship between the Employee and Salary tables in PostgreSQL?

  • Define EmpId as the PRIMARY KEY in the parent employee table.
  • Include an EmpId column in the child salary table with a FOREIGN KEY constraint using REFERENCES employee(EmpId).
  • This ensures every salary record corresponds to a valid existing employee and allows combined reporting via INNER JOIN.

4. Differentiate between DDL and DML commands in PostgreSQL with examples.

  • DDL (Data Definition Language): Defines or alters database structure (e.g., CREATE DATABASE, CREATE TABLE, ALTER TABLE, DROP TABLE).
  • DML (Data Manipulation Language): Reads and modifies table records (e.g., INSERT INTO, SELECT, UPDATE, DELETE).

4. मराठी टीप (Marathi Practical & Exam Revision Tip)

मराठी टीप: इयत्ता ११ वी IT प्रात्यक्षिक (PostgreSQL DBMS Queries – SOP 4) मध्ये पूर्ण गुण मिळवण्यासाठी या ५ गोष्टी लक्षात ठेवा — (१) नवीन डेटाबेस तयार केल्यावर नेहमी \c database_name; वापरून त्या डेटाबेसशी connect व्हा; (२) प्रत्येक SQL command च्या शेवटी semicolon (;) देणे आवश्यक आहे, पण \l, \dt, \d या meta-commands ला semicolon ची गरज नसते; (३) १० अंकी फोन नंबरसाठी INT ऐवजी BIGINT किंवा VARCHAR वापरा; (४) Text आणि Date ('YYYY-MM-DD') नेहमी single quotes ('...') मध्ये लिहा; (५) दोन टेबल्स जोडण्यासाठी parent table मध्ये PRIMARY KEY आणि child table मध्ये REFERENCES वापरा.

Frequently Asked Questions – Class 11 IT SOP 4

Q.1 Which PostgreSQL practicals are included in Balbharati Class 11 IT DBMS Skill Set?

The Balbharati Class 11 IT DBMS practicals cover creating the hospital database with a patients table (SOP 1), creating the school_master database with a students table containing at least 5 records (SOP 2), and creating Employee and Salary tables linked via Primary Key and Foreign Key constraints (SOP 3).

Q.2 What is the difference between a database and a table in PostgreSQL?

A database (such as school_master) is the top-level container that holds tables and schemas, whereas a table (such as students) sits inside a database and stores structured records organized into rows (tuples) and columns (fields).

Q.3 Why does my INSERT query fail if I omit single quotes around a student name or birth date?

In PostgreSQL SQL syntax, string values (like 'Aarav Sharma') and date values (like '2008-05-14') must be enclosed in single quotes so the parser recognizes them as text or date literals rather than column identifiers or arithmetic expressions.

Leave a Comment