Complete Summary and Solutions for SQL – NCERT Class XII Computer Science, Chapter 9 – Introduction, Data Definition, Data Manipulation, Queries, Joins, Functions, Questions, Answers
Detailed summary and explanation of Chapter 9 'SQL' from the Computer Science textbook for Class XII, covering the basics of SQL, data definition language (DDL), data manipulation language (DML), queries including select, insert, update and delete commands, different types of joins, SQL functions such as aggregate and scalar functions—along with all NCERT questions, answers, and exercises
Updated: 4 days ago

Structured Query Language (SQL)
Chapter 9: Computer Science - Ultimate Study Guide | NCERT Class 12 Notes, Questions, Code Examples & Quiz 2025
Full Chapter Summary & Detailed Notes - Structured Query Language (SQL) Class 12 NCERT
Overview & Key Concepts
- Chapter Goal: Understand RDBMS, SQL as query language, data types/constraints in MySQL, DDL (CREATE/ALTER), DML (INSERT/UPDATE/DELETE), queries (SELECT). Exam Focus: Tables 9.1-9.5, Figure 9.1, Activities 9.1-9.5; 2025 Updates: Emphasis on MySQL installation, case sensitivity. Fun Fact: Lev Manovich quote on data retrieval. Core Idea: SQL for database management; from file systems to relational queries. Real-World: StudentAttendance database. Expanded: All subtopics point-wise with evidence (e.g., CHAR vs VARCHAR), examples (e.g., CREATE TABLE STUDENT), debates (e.g., CHAR fixed vs VARCHAR variable).
- Wider Scope: From MySQL install to multi-table queries; sources: Activities, tables, figures.
- Expanded Content: Include modern aspects like SQL injection prevention; point-wise for recall; add 2025 relevance like cloud databases (e.g., MySQL on AWS).
Introduction & SQL Basics
- SQL Overview: Query language for RDBMS (MySQL, Oracle); descriptive, case-insensitive; DDL/DML/DQL.
- Benefits: No need for "how" – specify "what"; create/populate/query databases (e.g., StudentAttendance).
- Example: Retrieval: SELECT from table; evidence (queries in chapter).
- Practical Difficulties: Case sensitivity in Linux; Solutions: Consistent naming.
- Expanded: Evidence: Activity 9.1 other DBs; debates: SQL vs NoSQL; real: E-commerce queries.
Conceptual Diagram: SQL Flow
Flow: Install MySQL → CREATE DB/Table → INSERT Data → SELECT Query → Manipulate (UPDATE/DELETE). Ties to process in Section 9.4.
Why This Guide Stands Out
Comprehensive: All subtopics point-wise, MySQL commands integrated; 2025 with security best practices, processes analyzed for real DBs.
MySQL Installation & Basics
- Install: Download from dev.mysql.com; start service → mysql> prompt (Figure 9.1).
- Points: Case insensitive; end ; ; multiline -> prompt.
- Expanded: Evidence: Activity 9.1 RDBMS types; real: Open-source advantage.
Data Types & Constraints
- Data Types: CHAR(n) fixed, VARCHAR(n) variable, INT, FLOAT, DATE (Table 9.1).
- Constraints: NOT NULL, UNIQUE, DEFAULT, PRIMARY KEY, FOREIGN KEY (Table 9.2).
- Examples: RollNumber INT PRIMARY KEY; GUID CHAR(12) FOREIGN KEY.
- Expanded: Evidence: Tables 9.3-9.5; debates: CHAR vs VARCHAR efficiency.
Quick Code: Data Type Example
CREATE TABLE STUDENT (
RollNumber INT PRIMARY KEY,
SName VARCHAR(20) NOT NULL
);
Creates table with types/constraints.
SQL for Data Definition (DDL)
- CREATE DATABASE: CREATE DATABASE StudentAttendance; USE; SHOW DATABASES/TABLES.
- CREATE TABLE: Syntax with attributes; Example 9.1 STUDENT.
- DESCRIBE: View structure; ALTER for changes (add PK/FK/UNIQUE).
- Expanded: Evidence: Activities 9.3-9.5; real: Foreign key integrity.
Exam Code Studies
Example 9.1 CREATE; ALTER for keys; StudentAttendance schema.
Summary & Exercise
- Key Takeaways: SQL for RDBMS; types/constraints ensure data integrity; DDL defines schema.
- Exercise Tease: Justify CHAR vs VARCHAR; examples for constraints; code for CREATE/ALTER.
Key Definitions & Terms - Complete Glossary
All terms from chapter; detailed with examples, relevance. Expanded: 30+ terms grouped by subtopic; added advanced like "Composite Key", "DDL" for depth/easy flashcards.
SQL
Structured Query Language. Ex: SELECT. Relevance: RDBMS interaction.
RDBMS
Relational DB Management System. Ex: MySQL. Relevance: Stores relations.
Data Type
Value type for attribute. Ex: INT. Relevance: Operations allowed.
CHAR(n)
Fixed string. Ex: CHAR(12) GUID. Relevance: Padded spaces.
VARCHAR(n)
Variable string. Ex: VARCHAR(20) SName. Relevance: Efficient storage.
INT
Integer. Ex: RollNumber. Relevance: Numeric ops.
FLOAT
Decimal number. Ex: Scores. Relevance: Precision.
DATE
Date format. Ex: 'YYYY-MM-DD'. Relevance: Time data.
NOT NULL
No missing values. Ex: SName. Relevance: Required data.
UNIQUE
Distinct values. Ex: GPhone. Relevance: No duplicates.
DEFAULT
Auto value. Ex: Default 'P'. Relevance: Fallback.
PRIMARY KEY
Unique identifier. Ex: RollNumber. Relevance: Row ID.
FOREIGN KEY
Ref to PK. Ex: GUID in STUDENT. Relevance: Relations.
DDL
Data Definition Language. Ex: CREATE. Relevance: Schema.
Relation
Table. Ex: STUDENT. Relevance: Data structure.
Attribute
Column. Ex: SName. Relevance: Data field.
Constraint
Value restriction. Ex: NOT NULL. Relevance: Integrity.
Composite Key
Multi-attribute PK. Ex: AttendanceDate + RollNumber. Relevance: Unique combo.
SHOW DATABASES
List DBs. Ex: After CREATE. Relevance: Verify.
USE
Select DB. Ex: USE StudentAttendance. Relevance: Context.
SHOW TABLES
List tables. Ex: Empty set initial. Relevance: Check schema.
DESCRIBE
Table structure. Ex: DESC STUDENT. Relevance: View types/keys.
ALTER TABLE
Modify schema. Ex: ADD PRIMARY KEY. Relevance: Changes.
mysql> Prompt
SQL shell. Ex: Figure 9.1. Relevance: Interactive.
StudentAttendance
Example DB. Ex: Tables STUDENT/GUARDIAN/ATTENDANCE. Relevance: Case study.
Query Language
Access/manipulate DB. Ex: SQL. Relevance: No app programs needed.
Tip: Group by types/constraints; examples for recall. Depth: Debates (e.g., PK vs UNIQUE). Errors: Mismatched FK types. Historical: SQL standards. Interlinks: To Ch8 RDBMS. Advanced: Indexes. Real-Life: School DBs. Graphs: Tables 9.1-9.5. Coherent: Evidence → Interpretation. For easy learning: Flashcard per term with code.
60+ Questions & Answers - NCERT Based (Class 12) - From Exercises & Variations
Based on chapter + expansions. Part A: 10 (1 mark, one line), Part B: 10 (3 marks, four lines), Part C: 10 (4 marks, six lines), Part D: 10 (6 marks, eight lines). Answers point-wise in black text. Include code where apt.
Part A: 1 Mark Questions (10 Qs - Short)
1. What is SQL?
Structured Query Language.
2. Define RDBMS.
Relational Database Management System.
3. Name one data type in MySQL.
VARCHAR.
4. What does NOT NULL do?
No missing values.
5. Purpose of PRIMARY KEY?
Unique identifier.
6. What is DDL?
Data Definition Language.
7. Command to select DB?
USE.
8. Role of DESCRIBE?
View structure.
9. What is ALTER for?
Modify schema.
10. Example of FOREIGN KEY?
GUID in STUDENT.
Part B: 3 Marks Questions (10 Qs - Medium, Exactly 4 Lines Each)
1. Differentiate CHAR vs VARCHAR.
- CHAR fixed, padded.
- VARCHAR variable, no pad.
- Ex: CHAR(10) 'city' spaces.
- Efficiency: VARCHAR saves space.
2. List 3 constraints with uses.
- UNIQUE: Distinct values.
- PRIMARY KEY: Unique ID.
- FOREIGN KEY: Relation link.
- Ex: GPhone UNIQUE.
3. Explain CREATE DATABASE syntax.
- CREATE DATABASE name;
- Creates empty DB.
- Ex: StudentAttendance.
- USE to select.
4. What is DESCRIBE? Give example.
- Shows table structure.
- Ex: DESC STUDENT.
- Fields: Type/Null/Key.
- Verify schema.
5. Need for constraints.
- Ensure data correctness.
- Integrity/relations.
- Optional but key.
- Ex: NOT NULL required.
6. Process of adding PK.
- ALTER TABLE ADD PRIMARY KEY(attr).
- Composite: (attr1, attr2).
- Ex: GUARDIAN GUID.
- Unique/Non-null.
7. Basic CREATE TABLE syntax.
- CREATE TABLE name(attr type constraint);
- Ex: STUDENT RollNumber INT.
- Degree: Column count.
- End ;.
8. Use of FOREIGN KEY.
- Links tables.
- ALTER ADD FOREIGN KEY(ref) REFERENCES table(attr).
- Ex: STUDENT GUID to GUARDIAN.
- Same types.
9. Role of UNIQUE constraint.
- No duplicates.
- ALTER ADD UNIQUE(attr).
- Ex: GPhone.
- Nullable unless NOT NULL.
10. MySQL case sensitivity.
- Linux: Sensitive.
- Windows: Insensitive.
- Practice: Consistent cases.
- SQL statements insensitive.
Part C: 4 Marks Questions (10 Qs - Medium-Long, Exactly 6 Lines Each)
1. Explain data types with examples.
- CHAR: Fixed, padded.
- VARCHAR: Variable.
- INT: Integer 4 bytes.
- DATE: 'YYYY-MM-DD'.
- Ex: SName VARCHAR(20).
- Operations based on type.
2. Describe 4 constraints.
- DEFAULT: Auto value.
- PRIMARY KEY: Unique ID.
- FOREIGN KEY: Relation.
- UNIQUE: Distinct.
- Ex: Table 9.2.
- Ensure correctness.
3. How to install MySQL? Code example.
- Download dev.mysql.com.
- Start service → mysql>.
- Ex: Figure 9.1 prompt.
- Activity 9.1 other DBs.
- Open-source.
- Shell interactive.
4. Explain CREATE TABLE with program.
- Syntax: CREATE TABLE (attrs).
- Ex: Example 9.1 STUDENT.
- PK at end.
- Multiline ->.
- SHOW TABLES verify.
- Activity 9.4.
5. Outline ALTER process.
- ALTER TABLE ADD constraint.
- PK/FK/UNIQUE.
- Ex: Add PK GUARDIAN.
- FK rules: Referenced PK.
- Activity 9.5.
- Modify schema.
6. STUDENT table types/constraints.
- RollNumber INT PK.
- SName VARCHAR(20) NOT NULL.
- SDateofBirth DATE NOT NULL.
- GUID CHAR(12) FK.
- Table 9.3.
- Integrity.
7. Use of composite PK.
- Multi attrs unique.
- Ex: ATTENDANCE (Date, Roll).
- ALTER ADD PK (attrs).
- Table 9.5.
- No single unique.
- Relations.
8. Differentiate DDL vs DML.
- DDL: Define schema (CREATE).
- DML: Manipulate data (INSERT).
- Ex: CREATE vs UPDATE.
- DDL changes structure.
- Section 9.4.
- Both SQL parts.
9. Why constraints?
- Restrict invalid data.
- Integrity/accuracy.
- Optional per attr.
- Ex: PK unique.
- Table 9.2.
- Prevent errors.
10. SHOW commands uses.
- SHOW DATABASES: List DBs.
- SHOW TABLES: List tables.
- Ex: After CREATE.
- Verify empty.
- Activity 9.3.
- Debugging.
Part D: 6 Marks Questions (10 Qs - Long, Exactly 8 Lines Each)
1. Justify SQL over file systems.
- No app programs needed.
- Query language for access.
- Ex: RDBMS like MySQL.
- Relations/tables.
- Manipulate/retrieve.
- Intro section.
- Efficient search.
- Quote Manovich.
2. When used: CHAR, VARCHAR, INT, DATE. Examples.
- CHAR: Fixed e.g. GUID(12).
- VARCHAR: Variable e.g. Name(20).
- INT: Numbers e.g. Roll.
- DATE: Dates e.g. Birth.
- Table 9.1.
- Activity 9.2.
- Ops restricted.
- Storage bytes.
3. Use ALTER to add FK; code.
- ALTER TABLE ADD FOREIGN KEY(attr) REFERENCES table(attr).
- Ex: STUDENT GUID to GUARDIAN.
- Referenced PK.
- Same types.
- Activity 9.5.
- Integrity.
- Figure 8.4 prev.
- Links data.
ALTER TABLE STUDENT
ADD FOREIGN KEY(GUID) REFERENCES GUARDIAN(GUID);
4. Use UNIQUE in GUARDIAN; code.
- ALTER TABLE ADD UNIQUE(GPhone).
- No duplicates.
- Ex: Phone numbers.
- Table 9.4.
- Nullable OK.
- With NOT NULL PK-like.
- Data correctness.
- Section 9.4.4(C).
ALTER TABLE GUARDIAN ADD UNIQUE(GPhone);
5. Define: Data Type, Constraint, Relation.
- Data Type: Value kind/ops.
- Ex: INT numeric.
- Constraint: Value restriction.
- Ex: PRIMARY KEY unique.
- Relation: Table/attributes.
- Ex: STUDENT.
- Schema definition.
- Section 9.3.
6. Explain CREATE TABLE; code.
- Syntax: CREATE TABLE (attr type [constraint]).
- Ex: Example 9.1 STUDENT.
- PK end.
- Multiline ; end.
- Activity 9.4 others.
- Empty initial.
- Degree N columns.
- Section 9.4.2.
CREATE TABLE STUDENT(
RollNumber INT,
SName VARCHAR(20),
PRIMARY KEY (RollNumber)
);
7. Fill blanks in code; explain.
- CREATE TABLE GUARDIAN(GUID CHAR(12) PRIMARY KEY).
- Code: Types/constraints.
- ALTER ADD UNIQUE/FOREIGN.
- Full schema: Tables 9.3-9.5.
- Relations link.
- StudentAttendance case.
- Integrity ensure.
- Activities 9.4-9.5.
CREATE TABLE GUARDIAN(
GUID CHAR(12) PRIMARY KEY,
GName VARCHAR(20) NOT NULL
);
8. Wrong types in table; fix with ALTER. Code.
- ALTER TABLE MODIFY attr new_type.
- Ex: Change INT to FLOAT.
- Compatibility check.
- Section 9.4.4.
- Data loss risk.
- Verify DESC.
- Schema evolve.
- Real DB changes.
ALTER TABLE STUDENT MODIFY RollNumber FLOAT;
9. Use composite PK in ATTENDANCE.
- ALTER ADD PRIMARY KEY(Date, Roll).
- Unique combo.
- Ex: Table 9.5.
- No single PK.
- FK to STUDENT.
- Relations maintain.
- Activity 9.5.
- Data uniqueness.
10. SQL in RDBMS; MySQL specifics.
- Query for relational DBs.
- MySQL: Open-source, install prompt.
- Case: Linux sensitive.
- Ex: CREATE/USE.
- 2025: Cloud integration.
- Efficient management.
- Section 9.1-9.2.
- Popular major.
Tip: Include code in ans; practice MySQL. Additional 30 Qs: Variations on tables, schema scenarios.
Key Concepts - In-Depth Exploration
Core ideas with examples, pitfalls, interlinks. Expanded: All concepts with steps/examples/pitfalls for easy learning. Depth: Debates, analysis.
SQL
Steps: 1. Install MySQL, 2. CREATE DB, 3. Query. Ex: Figure 9.1. Pitfall: No ;. Interlink: RDBMS. Depth: Descriptive.
Data Types
Steps: 1. Choose per data, 2. Declare in CREATE. Ex: Table 9.1. Pitfall: Wrong size. Interlink: Constraints. Depth: Ops restricted.
Constraints
Steps: 1. Add in CREATE/ALTER, 2. Ensure integrity. Ex: Table 9.2. Pitfall: FK mismatch. Interlink: PK/FK. Depth: 5 common.
CREATE DATABASE
Steps: 1. CREATE name;, 2. USE. Ex: StudentAttendance. Pitfall: Exists error. Interlink: SHOW. Depth: Empty start.
CREATE TABLE
Steps: 1. Define attrs/types, 2. PK. Ex: Example 9.1. Pitfall: No comma. Interlink: ALTER. Depth: Schema define.
DESCRIBE
Steps: 1. DESC table;. Ex: STUDENT output. Pitfall: Wrong name. Interlink: Verify. Depth: Fields details.
ALTER TABLE
Steps: 1. ADD constraint, 2. MODIFY type. Ex: Add PK. Pitfall: Invalid ref. Interlink: FK rules. Depth: Changes.
PRIMARY KEY
Steps: 1. Unique/non-null, 2. Add ALTER. Ex: RollNumber. Pitfall: Duplicates. Interlink: Composite. Depth: ID row.
FOREIGN KEY
Steps: 1. Ref PK, 2. Same type. Ex: GUID. Pitfall: No referenced. Interlink: Relations. Depth: Link tables.
UNIQUE
Steps: 1. Add ALTER, 2. No dups. Ex: GPhone. Pitfall: With NULL. Interlink: PK subset. Depth: Distinct.
SHOW TABLES
Steps: 1. After USE, 2. List. Ex: student. Pitfall: Empty set. Interlink: CREATE verify. Depth: DB contents.
Composite Key
Steps: 1. Multi attrs, 2. ADD PK (a1,a2). Ex: ATTENDANCE. Pitfall: Partial dup. Interlink: PK. Depth: Combo unique.
Case Sensitivity
Steps: 1. Linux yes, Windows no. Ex: Names. Pitfall: Mismatch. Interlink: Best practice. Depth: OS diff.
Multiline SQL (Advanced)
Steps: 1. No ; first line, 2. -> prompt. Ex: Long CREATE. Pitfall: Forget ;. Interlink: Shell. Depth: Interactive.
StudentAttendance (Advanced)
Steps: 1. CREATE tables, 2. Add keys. Ex: 3 tables. Pitfall: No FK order. Interlink: Ch8. Depth: Example schema.
Advanced: SQL injection, views. Pitfalls: Constraint violations. Interlinks: To Ch8 relations. Real: DB design. Depth: 15 concepts details. Examples: Real outputs. Graphs: Tables 9.3-9.5. Errors: Type mismatch. Tips: Steps evidence; compare CHAR/VARCHAR.
Code Examples & Programs - From Text with Simple Explanations
Expanded with evidence, analysis; focus on applications. Added variations for practice.
Example 1: CREATE DATABASE (Section 9.4.1)
Simple Explanation: Create empty DB.
CREATE DATABASE StudentAttendance;
- Step 1: Run → Query OK.
- Step 2: SHOW DATABASES verify.
- Step 3: USE to select.
- Simple Way: Base for tables.
Example 2: CREATE TABLE STUDENT (Example 9.1)
Simple Explanation: Define schema.
CREATE TABLE STUDENT(
RollNumber INT,
SName VARCHAR(20),
SDateofBirth DATE,
GUID CHAR(12),
PRIMARY KEY (RollNumber)
);
- Step 1: Types/constraints.
- Step 2: Query OK.
- Step 3: DESC view.
- Simple Way: Student data.
Example 3: ALTER ADD PRIMARY KEY (Section 9.4.4)
Simple Explanation: Add key post-create.
ALTER TABLE GUARDIAN ADD PRIMARY KEY (GUID);
- Step 1: Existing table.
- Step 2: Query OK.
- Step 3: DESC check Key PRI.
- Simple Way: Unique ID.
Example 4: ALTER ADD FOREIGN KEY (Section 9.4.4)
Simple Explanation: Link tables.
ALTER TABLE STUDENT
ADD FOREIGN KEY(GUID) REFERENCES GUARDIAN(GUID);
- Step 1: Referenced exists.
- Step 2: Query OK.
- Step 3: Integrity enforce.
- Simple Way: Relations.
Example 5: DESCRIBE STUDENT (Section 9.4.3)
Simple Explanation: View structure.
DESCRIBE STUDENT;
- Step 1: Run → Table output.
- Step 2: Fields/Type/Null/Key.
- Step 3: Verify changes.
- Simple Way: Debug schema.
Example 6: Composite PK + FK (Section 9.4.4)
Simple Explanation: Multi-key (2025 secure DBs).
ALTER TABLE ATTENDANCE
ADD PRIMARY KEY(AttendanceDate, RollNumber);
ALTER TABLE ATTENDANCE
ADD FOREIGN KEY(RollNumber) REFERENCES STUDENT(RollNumber);
- Step 1: Combo unique.
- Step 2: Link to STUDENT.
- Step 3: Integrity.
- Simple Way: Attendance track.
Tip: Run in MySQL; troubleshoot (e.g., no ref error). Added for ALTER, full schemas.
Interactive Quiz - Master SQL
10 MCQs in full sentences; 80%+ goal. Covers types, constraints, commands.
Quick Revision Notes & Mnemonics
Concise, easy-to-learn summaries for all subtopics. Structured in tables for quick scan: Key points, examples, mnemonics. Covers SQL basics, types, constraints, DDL. Bold key terms; short phrases for fast reading.
| Subtopic | Key Points | Examples | Mnemonics/Tips |
|---|---|---|---|
| SQL Basics |
|
CREATE DB; Activity 9.1. | SQL (Select/Query/Lang). Tip: "SQL Says What, Not How" – Descriptive. |
| Data Types (5) |
|
Table 9.1; GUID CHAR(12). | CVIFD (Char Varchar Int Float Date). Tip: "Char Very Int Float Date" – Common types. |
| Constraints (5) |
|
Table 9.2; Roll PK. | NU DPF (Not Unique Default Primary Foreign). Tip: "No Unique Defaults Primary Foreign" – Integrity rules. |
| DDL Commands |
|
Example 9.1; ALTER PK. | CADS (Create Alter Describe Show). Tip: "Create Alter Describe Show" – Schema ops. |
| Keys |
|
ATTENDANCE (Date,Roll). | PF C (Primary Foreign Composite). Tip: "Primary Foreign Combo" – Unique links. |
| StudentAttendance |
|
Tables 9.3-9.5. | SGA (Student Guardian Attendance). Tip: "Student Guards Attendance" – Example DB. |
Overall Tip: Use CVIFD-NU DPF-CADS for full scan (5 mins). Flashcards: Front (term), Back (points + mnemonic). Print table for wall revision. Covers 100% chapter – easy for exams!
Key Terms & Processes - All Key
Expanded table 30+ rows; quick ref. Added advanced (e.g., Composite Key, Multiline SQL).
| Term/Process | Description | Example | Usage |
|---|---|---|---|
| SQL | Query language | CREATE | DB interact |
| RDBMS | Relational system | MySQL | Store relations |
| Data Type | Value kind | INT | Ops define |
| CHAR | Fixed string | CHAR(12) | Padded |
| VARCHAR | Variable string | VARCHAR(20) | Efficient |
| INT | Integer | RollNumber | Numbers |
| FLOAT | Decimal | Scores | Precision |
| DATE | Date | Birth | YYYY-MM-DD |
| NOT NULL | No missing | SName | Required |
| UNIQUE | Distinct | GPhone | No dups |
| DEFAULT | Auto value | 'P' | Fallback |
| PRIMARY KEY | Unique ID | RollNumber | Row identify |
| FOREIGN KEY | Ref PK | GUID | Link tables |
| DDL | Define schema | CREATE | Structure |
| Relation | Table | STUDENT | Data store |
| Attribute | Column | SName | Field |
| Constraint | Restriction | NOT NULL | Integrity |
| Composite Key | Multi PK | Date+Roll | Combo unique |
| SHOW DATABASES | List DBs | After CREATE | Verify |
| USE | Select DB | StudentAttendance | Context |
| SHOW TABLES | List tables | Empty set | Check |
| DESCRIBE | Structure | DESC STUDENT | View |
| ALTER TABLE | Modify | ADD PK | Changes |
| mysql> Prompt | Shell | Figure 9.1 | Interactive |
| StudentAttendance | Example DB | 3 tables | Case study |
| Query Language | DB access | SQL | No programs |
| Multiline SQL | -> prompt | Long CREATE | Continue |
| Case Sensitivity | OS diff | Linux yes | Naming |
| Degree | Column count | N attrs | Schema |
| Referenced Table | PK source | GUARDIAN | FK target |
| Referencing Table | FK holder | STUDENT | Link from |
Tip: Examples memory; sort subtopic. Easy: Table scan. Added 10 rows depth depth.
SQL Processes Step-by-Step
Step-by-step breakdowns of core processes, structured as full questions followed by detailed answers with steps. Visual descriptions for easy understanding; focus on actionable Q&A with examples from chapter.
Question 1: How to install and start using MySQL as in Figure 9.1?
- Step 1: Download from dev.mysql.com.
- Step 2: Install/start service.
- Step 3: mysql> prompt ready.
- Step 4: Type commands ; end.
- Step 5: Multiline -> continue.
- Step 6: Activity 9.1 explore.
Visual: Download → Prompt → Query Loop. Example: CREATE first.
Question 2: What steps to create and select a database like StudentAttendance?
- Step 1: CREATE DATABASE name;.
- Step 2: Query OK.
- Step 3: SHOW DATABASES list.
- Step 4: USE name;.
- Step 5: Database changed.
- Step 6: SHOW TABLES empty.
Visual: CREATE → List → Select Path. Example: Activity 9.3 verify.
Question 3: How to create a table with types/constraints as in Example 9.1?
- Step 1: Identify attrs/types (Table 9.3).
- Step 2: CREATE TABLE (attr type constraint).
- Step 3: PK at end.
- Step 4: Query OK.
- Step 5: DESC view.
- Step 6: Activity 9.4 others.
Visual: Attr List → CREATE → Verify. Example: STUDENT table.
Question 4: What is the process to add a foreign key using ALTER?
- Step 1: Referenced table/PK exists.
- Step 2: ALTER TABLE ADD FOREIGN KEY(attr) REFERENCES table(attr).
- Step 3: Types match.
- Step 4: Query OK.
- Step 5: DESC Key MUL.
- Step 6: Activity 9.5 ATTENDANCE.
Visual: Check Ref → ADD FK → Integrity. Example: STUDENT to GUARDIAN.
Question 5: How to add UNIQUE constraint post-creation?
- Step 1: Existing table.
- Step 2: ALTER TABLE ADD UNIQUE(attr).
- Step 3: No current dups.
- Step 4: Query OK.
- Step 5: DESC Key UNI.
- Step 6: Ex: GUARDIAN GPhone.
Visual: Table → ADD UNIQUE → Distinct Enforce. Example: Section 9.4.4(C).
Question 6: Outline steps for composite primary key.
- Step 1: Identify multi attrs unique.
- Step 2: ALTER ADD PRIMARY KEY(a1,a2).
- Step 3: No nulls/dups.
- Step 4: Query OK.
- Step 5: DESC both PRI.
- Step 6: Ex: ATTENDANCE.
Visual: Attrs Combo → ADD PK → Unique Pair. Example: Table 9.5.
Tip: Treat as FAQ; apply to MySQL. Easy: Q → Steps + Visual. Full Q&A for exam-like practice.
Group Discussions
No forum posts available.
Easily Share with Your Tribe


