PGDCA, BCA, B-Tech, MCA, M-Tech, B.Sc computer science राजस्थान सूचना सहायक व कंप्यूटर शिक्षक विशेष नोट्स: इस अध्याय में हम SQL DDL Commands: CREATE TABLE, ALTER TABLE, DROP TABLE, TRUNCATE (SQL DDL कमांड्स: CREATE, ALTER, DROP और TRUNCATE में अंतर) की संपूर्ण थ्योरी, मुख्य तकनीकी बिंदु, तुलनात्मक तालिका और विगत परीक्षाओं के पैटर्न पर आधारित 20 अति-महत्वपूर्ण बहुविकल्पीय प्रश्न (MCQs) विस्तृत हिंदी व अंग्रेजी व्याख्या सहित पढ़ेंगे।
Overview: SQL Data Definition Language (DDL) commands—CREATE, ALTER, DROP, and TRUNCATE—define, modify, and deallocate database schema objects such as tables, indexes, and constraints inside the system catalog. Because DDL statements alter structural metadata, engines like MySQL and Oracle issue an implicit COMMIT around them, whereas PostgreSQL supports transactional DDL rollbacks.
अध्याय सार: SQL के डेटा डेफिनिशन लैंग्वेज (DDL) कमांड्स—CREATE, ALTER, DROP और TRUNCATE—सिस्टम कैटलॉग में टेबल, इंडेक्स और कंस्ट्रेंट्स की संरचना बनाने, बदलने व समाप्त करने का कार्य करते हैं। चूँकि DDL कमांड स्कीमा मेटाडेटा बदलते हैं, इसलिए MySQL और Oracle में ये स्वतः (Implicit) COMMIT कर देते हैं, जबकि PostgreSQL में इन्हें रोलबैक भी किया जा सकता है।
SQL DDL Commands: CREATE TABLE, ALTER TABLE, DROP TABLE, TRUNCATE: Detailed Notes & Architecture (SQL DDL कमांड्स: CREATE, ALTER, DROP और TRUNCATE में अंतर)
1. CREATE TABLE: Columns, Constraints, and CTAS Cloning (CREATE TABLE: कॉलम, कंस्ट्रेंट्स और टेबल क्लोनिंग)
[EN] The CREATE TABLE command registers a new relation inside the Data Dictionary by specifying column names, data types, and integrity constraints. Constraints may be column-level or table-level, including PRIMARY KEY, NOT NULL, UNIQUE, CHECK(condition), DEFAULT expr, and FOREIGN KEY(col) REFERENCES Parent(pk) ON DELETE CASCADE/SET NULL. SQL also supports CREATE TABLE NewTbl AS SELECT ... FROM OldTbl (CTAS) to instantiate and populate a table directly from a query result, though constraints like primary keys usually are not copied automatically.
[HI] CREATE TABLE कमांड डेटा डिक्शनरी में कॉलम के नाम, डेटा टाइप और इंटेग्रिटी कंस्ट्रेंट्स के साथ एक नई टेबल बनाता है। इसमें PRIMARY KEY, NOT NULL, UNIQUE, CHECK, DEFAULT और FOREIGN KEY (REFERENCES व ON DELETE नियम सहित) लागू किए जा सकते हैं। इसके अलावा CREATE TABLE NewTbl AS SELECT ... (CTAS) द्वारा किसी क्वेरी के आउटपुट से सीधे नई टेबल बनाई जा सकती है, यद्यपि इसमें मूल टेबल के की-कंस्ट्रेंट्स स्वतः कॉपी नहीं होते।
2. ALTER TABLE: Evolving Existing Table Schemas (ALTER TABLE: मौजूदा टेबल संरचना में परिवर्तन)
[EN] ALTER TABLE modifies an already populated table's structure without destroying existing rows. Standard operations include ADD col datatype [constraint], DROP COLUMN col, RENAME COLUMN old TO new, and ADD/DROP CONSTRAINT name. Changing a column's data type or nullability uses MODIFY COLUMN in MySQL/Oracle or ALTER COLUMN ... TYPE in PostgreSQL/SQL Server. Adding a new NOT NULL column to a non-empty table requires supplying a DEFAULT value (or creating it nullable first, updating rows, then enforcing NOT NULL).
[HI] ALTER TABLE बिना मौजूदा पंक्तियाँ नष्ट किए किसी टेबल की संरचना को संशोधित करता है। इसके प्रमुख उप-कमांड ADD (नया कॉलम या कंस्ट्रेंट जोड़ना), DROP COLUMN (कॉलम हटाना), RENAME COLUMN (नाम बदलना) तथा MODIFY / ALTER COLUMN (डेटा टाइप या साइज बदलना) हैं। यदि भरी हुई टेबल में नया NOT NULL कॉलम जोड़ना हो, तो साथ में DEFAULT मान देना अनिवार्य होता है।
3. TRUNCATE TABLE vs DROP TABLE and Foreign Key Dependencies (TRUNCATE TABLE बनाम DROP TABLE और फॉरेन की बाधाएँ)
[EN] TRUNCATE TABLE is a DDL command that removes every row from a table rapidly by deallocating its data pages and resetting any IDENTITY or AUTO_INCREMENT counter back to its seed, while keeping columns, indexes, and permissions intact. DROP TABLE goes further, erasing all rows, indexes, triggers, permissions, and the schema entry itself from the catalog. Crucially, if another table holds an active FOREIGN KEY referencing a parent table, databases reject both TRUNCATE TABLE Parent and DROP TABLE Parent unless the child FK is dropped first or CASCADE is specified.
[HI] TRUNCATE TABLE एक DDL कमांड है जो डेटा पेज खाली करके सभी पंक्तियाँ अत्यंत तेजी से हटाता है और AUTO_INCREMENT / IDENTITY काउंटर को पुनः प्रारंभिक मान (Seed) पर ले आता है, किंतु टेबल की संरचना व कॉलम सुरक्षित रहते हैं। इसके विपरीत DROP TABLE डेटा के साथ-साथ पूरी टेबल परिभाषा, इंडेक्स, ट्रिगर और कैटलॉग प्रविष्टि मिटा देता है। यदि किसी पेरेंट टेबल पर सक्रिय FOREIGN KEY निर्भर हो, तो बिना CASCADE या FK हटाए उसे TRUNCATE या DROP नहीं किया जा सकता।
4. Implicit Auto-Commit, RENAME TABLE, and Transactional DDL (इम्प्लिसिट कमिट, RENAME और डेटाबेस इंजन अंतर)
[EN] In MySQL and Oracle, executing any DDL command (CREATE, ALTER, DROP, TRUNCATE, RENAME) automatically issues an implicit COMMIT before and after the DDL statement—meaning uncommitted DML inserts/updates performed earlier in the same session become permanently committed and cannot be rolled back! By contrast, PostgreSQL and SQL Server allow DDL inside explicit BEGIN ... ROLLBACK transactions. Meanwhile, RENAME TABLE old TO new updates only catalog metadata in O(1) time without copying stored rows.
[HI] MySQL और Oracle में कोई भी DDL कमांड (CREATE, ALTER, DROP, TRUNCATE) चलाने पर उसके पहले व बाद में स्वतः (Implicit) COMMIT हो जाता है—अर्थात उसी सेशन के पुराने अनकमिटेड DML बदलाव भी स्थायी हो जाते हैं जिन्हें ROLLBACK नहीं किया जा सकता। हालांकि PostgreSQL और SQL Server ट्रांज़ैक्शनल DDL रोलबैक की सुविधा देते हैं। वहीं RENAME TABLE केवल मेटाडेटा बदलकर O(1) समय में टेबल का नाम बदल देता है।
Syntax, Formula & Technical Example (SQL DDL Commands: CREATE TABLE, ALTER TABLE, DROP TABLE, TRUNCATE)
-- SQL DDL Lifecycle: CREATE, ALTER, TRUNCATE, RENAME, DROP
CREATE TABLE Course (
CourseID INT PRIMARY KEY,
Title VARCHAR(80) NOT NULL UNIQUE,
Credits INT DEFAULT 4 CHECK (Credits BETWEEN 1 AND 6)
);
ALTER TABLE Course ADD DeptCode VARCHAR(10) NOT NULL DEFAULT 'CS';
ALTER TABLE Course MODIFY Title VARCHAR(120) NOT NULL; -- MySQL/Oracle syntax
RENAME TABLE Course TO DeptCourse;
TRUNCATE TABLE DeptCourse; -- Removes all rows, keeps schema
DROP TABLE IF EXISTS DeptCourse; -- Destroys schema & catalog entry
SQL DDL Commands: CREATE TABLE, ALTER TABLE, DROP TABLE, TRUNCATE Quick Reference & Comparison Table
| DDL Command | Primary Structural Operation | Catalog & Transaction Impact |
|---|---|---|
| CREATE TABLE | Allocates new table schema, columns, and integrity constraints | Adds metadata to System Catalog; auto-commits in MySQL/Oracle |
| ALTER TABLE | Adds, drops, renames, or modifies columns and constraints | Retains existing row data while updating table definition |
| TRUNCATE TABLE | Deallocates all data pages and resets identity counter to seed | DDL bulk removal without WHERE; preserves empty table structure |
| DROP TABLE | Erases all rows, indexes, triggers, and schema definition | Removes object entry from catalog; table must be recreated |
SQL DDL Commands: CREATE TABLE, ALTER TABLE, DROP TABLE, TRUNCATE Top 20 Bilingual MCQs with Answers
Q1. Which set of SQL commands belongs exclusively to DDL (Data Definition Language)?
(निम्नलिखित में से कमांड्स का कौन सा समूह पूरी तरह DDL (Data Definition Language) से संबंधित है?)
(A) CREATE, UPDATE, SAVEPOINT, MERGE
(B) CREATE, ALTER, DROP, TRUNCATE, RENAME
(C) GRANT, REVOKE, COMMIT, ROLLBACK
(D) INSERT, UPDATE, DELETE, SELECT
Correct Answer: (B)
[EN] DDL defines and alters database objects; CREATE, ALTER, DROP, TRUNCATE, and RENAME all operate on schema metadata.
[HI] CREATE, ALTER, DROP, TRUNCATE और RENAME सभी टेबल/ऑब्जेक्ट की संरचना पर कार्य करने वाले DDL कमांड्स हैं।
Q2. Why is TRUNCATE TABLE classified as a DDL command rather than a DML command in SQL?
(SQL में TRUNCATE TABLE को DML के बजाय DDL कमांड क्यों माना जाता है?)
(A) It deallocates table storage extents/pages and resets metadata counters rather than deleting rows one by one
(B) Because it only updates user passwords
(C) Because it runs inside SELECT statements
(D) Because it supports a WHERE clause like UPDATE
Correct Answer: (A)
[EN] Unlike row-by-row DML DELETE, TRUNCATE reclaims storage allocation structures directly in metadata and resets identity seeds.
[HI] TRUNCATE एक-एक पंक्ति डिलीट करने के बजाय सीधे टेबल के स्टोरेज पेज खाली करता है और आइडेंटिटी मेटाडेटा रीसेट करता है, इसलिए यह DDL है।
Q3. What happens when you try to add a new NOT NULL column without a DEFAULT value to a table that already contains 500 rows?
(यदि किसी टेबल में पहले से 500 पंक्तियाँ हैं और आप बिना DEFAULT दिए ALTER TABLE ... ADD से नया NOT NULL कॉलम जोड़ें, तो क्या होगा?)
(A) The DBMS fills the column with zeros regardless of type
(B) The DBMS raises an error because existing 500 rows have no valid non-null value for the new column
(C) The DBMS drops the PRIMARY KEY silently
(D) The DBMS automatically deletes all 500 rows first
Correct Answer: (B)
[EN] Existing tuples would automatically receive NULL in the new column, violating NOT NULL—so a DEFAULT clause is mandatory on populated tables.
[HI] पुरानी 500 पंक्तियों के लिए नए कॉलम में स्वतः NULL आएगा जो NOT NULL नियम तोड़ेगा; अतः भरी टेबल में DEFAULT मान देना आवश्यक है।
Q4. Which clause safely avoids an error if you attempt to drop a table that might not exist?
(यदि कोई टेबल मौजूद न हो तब भी बिना एरर दिए DROP चलाने हेतु कौन सा क्लॉज उपयोग किया जाता है?)
(A) DROP TABLE IF EXISTS TableName;
(B) DROP TABLE IGNORE TableName;
(C) DELETE TABLE NULL TableName;
(D) DROP TABLE SAFE TableName;
Correct Answer: (A)
[EN] IF EXISTS instructs the SQL engine to issue at most a warning/notice rather than aborting a migration script when the table is absent.
[HI] DROP TABLE IF EXISTS लिखने से टेबल न मिलने पर भी स्क्रिप्ट एरर देकर रुकती नहीं है।
Q5. What occurs to an uncommitted INSERT executed right before running CREATE TABLE or ALTER TABLE in MySQL or Oracle?
(MySQL या Oracle में किसी अनकमिटेड INSERT के ठीक बाद CREATE TABLE या ALTER TABLE चलाने पर उस INSERT का क्या होता है?)
(A) It is automatically rolled back before DDL runs
(B) It gets implicitly committed automatically and can no longer be rolled back
(C) It triggers a syntax error in every session
(D) It stays pending until DROP TABLE is called
Correct Answer: (B)
[EN] MySQL and Oracle wrap DDL statements with an implicit COMMIT beforehand, permanently persisting pending DML changes in that session.
[HI] MySQL और Oracle में DDL कमांड चलने से पहले स्वतः Implicit COMMIT हो जाता है, जिससे पिछला अनकमिटेड INSERT पक्का सेव हो जाता है।
Q6. Which ALTER TABLE clause adds a primary key constraint named pk_emp to an existing Employee(EmpID) table?
(मौजूदा Employee(EmpID) टेबल पर pk_emp नाम का प्राइमरी की कंस्ट्रेंट जोड़ने का सही ALTER TABLE सिंटैक्स कौन सा है?)
(A) ALTER TABLE Employee CREATE KEY pk_emp (EmpID);
(B) INSERT CONSTRAINT pk_emp ON Employee(EmpID);
(C) ALTER TABLE Employee ADD CONSTRAINT pk_emp PRIMARY KEY (EmpID);
(D) UPDATE TABLE Employee SET PRIMARY KEY = EmpID;
Correct Answer: (C)
[EN] Standard SQL uses ALTER TABLE tbl ADD CONSTRAINT name PRIMARY KEY (col).
[HI] मानक SQL में कंस्ट्रेंट जोड़ने हेतु ALTER TABLE टेबल ADD CONSTRAINT नाम PRIMARY KEY (कॉलम) लिखा जाता है।
Q7. When using CTAS (CREATE TABLE Backup AS SELECT * FROM Orders), what happens to constraints such as FOREIGN KEY and CHECK in most SQL engines?
(CTAS (CREATE TABLE Backup AS SELECT * FROM Orders) चलाने पर अधिकांश SQL इंजनों में FOREIGN KEY या CHECK कंस्ट्रेंट्स का क्या होता है?)
(A) Only constraints copy while rows stay empty
(B) Data and column types copy over, while table constraints like Foreign Keys and Triggers are NOT copied automatically
(C) Every Foreign Key, Index, and Trigger is duplicated identically
(D) CTAS deletes the original Orders table
Correct Answer: (B)
[EN] CTAS materializes query output into a new table schema; aside from basic NOT NULL propagation in some engines, keys/indexes/triggers must be added explicitly.
[HI] CTAS से केवल कॉलम प्रकार और पंक्तियाँ कॉपी होती हैं; प्राइमरी/फॉरेन की, इंडेक्स व ट्रिगर स्वतः कॉपी नहीं होते।
Q8. Which command removes a column named Fax from the Suppliers table permanently?
(Suppliers टेबल से Fax कॉलम को स्थायी रूप से हटाने का मानक SQL कमांड कौन सा है?)
(A) DROP Fax FROM Suppliers;
(B) DELETE COLUMN Fax FROM Suppliers;
(C) TRUNCATE COLUMN Fax ON Suppliers;
(D) ALTER TABLE Suppliers DROP COLUMN Fax;
Correct Answer: (D)
[EN] Removing an existing column modifies table schema and uses ALTER TABLE tbl DROP COLUMN col.
[HI] किसी मौजूदा कॉलम को हटाने के लिए ALTER TABLE टेबल DROP COLUMN कॉलम सिंटैक्स प्रयोग होता है।
Q9. Why might DROP TABLE Department fail with a constraint error?
(DROP TABLE Department कमांड किस कारण से कंस्ट्रेंट एरर देकर विफल हो सकता है?)
(A) Because Department contains more than 100 rows
(B) Another child table (such as Employee) holds a FOREIGN KEY referencing Department
(C) Because DROP TABLE only works on empty tables
(D) Because Department has a NOT NULL column
Correct Answer: (B)
[EN] Referential integrity forbids dropping a parent table while active foreign keys point to it unless CASCADE (dialect-dependent) or child FK removal is applied first.
[HI] यदि कोई चाइल्ड टेबल FOREIGN KEY द्वारा Department से जुड़ी है, तो बिना फॉरेन की हटाए या CASCADE के पेरेंट टेबल ड्रॉप नहीं की जा सकती।
Q10. Which of the following is NOT true about SQL DDL commands?
(SQL DDL कमांड्स के विषय में निम्नलिखित में से कौन सा कथन सत्य नहीं है?)
(A) DDL commands update metadata inside the System Catalog / Data Dictionary
(B) PostgreSQL allows rolling back DDL commands inside an explicit transaction block
(C) DDL commands cannot create or drop indexes or views—only tables
(D) TRUNCATE TABLE keeps the column definitions intact while removing all rows
Correct Answer: (C)
[EN] DDL encompasses ALL schema objects: CREATE/DROP INDEX, CREATE/DROP VIEW, CREATE/DROP SCHEMA, triggers, and sequences—not just tables.
[HI] DDL केवल टेबल्स तक सीमित नहीं है; व्यू (VIEW), इंडेक्स (INDEX), स्कीमा और सीक्वेंस बनाना/हटाना भी DDL में ही आता है।
Q11. Which constraint inside CREATE TABLE ensures column Age never accepts a negative value?
(CREATE TABLE के अंदर कौन सा कंस्ट्रेंट सुनिश्चित करता है कि Age कॉलम में कभी ऋणात्मक मान न डले?)
(A) FOREIGN KEY (Age >= 0)
(B) DEFAULT (Age >= 0)
(C) CHECK (Age >= 0)
(D) UNIQUE (Age >= 0)
Correct Answer: (C)
[EN] The CHECK constraint enforces arbitrary row-level boolean predicates on column values upon INSERT and UPDATE.
[HI] CHECK (Age >= 0) कंस्ट्रेंट प्रत्येक INSERT व UPDATE के समय मान की वैधता शर्त की जांच करता है।
Q12. How does RENAME TABLE OldName TO NewName perform so quickly even on a 50 GB table?
(50 GB की विशाल टेबल पर भी RENAME TABLE OldName TO NewName पलक झपकते (O(1) में) कैसे पूरा हो जाता है?)
(A) It compresses the table to 1 KB first
(B) It deletes all rows before renaming
(C) It bypasses disk writes entirely forever
(D) It updates only the table name entry in the System Catalog metadata without copying data pages
Correct Answer: (D)
[EN] Renaming changes the logical identifier pointer in catalog metadata while leaving underlying data files/pages untouched.
[HI] नाम बदलने पर डेटा पेज कॉपी नहीं होते, केवल सिस्टम कैटलॉग के मेटाडेटा में टेबल का नाम बदला जाता है।
Q13. What is the effect of specifying ON DELETE CASCADE on a FOREIGN KEY inside CREATE TABLE?
(CREATE TABLE में FOREIGN KEY पर ON DELETE CASCADE लगाने का क्या प्रभाव पड़ता है?)
(A) Deleting a child row deletes the entire parent table
(B) Deleting a referenced parent row automatically deletes all matching child rows referencing it
(C) It blocks all DELETE commands on both tables
(D) It converts the Foreign Key into a CHECK constraint
Correct Answer: (B)
[EN] ON DELETE CASCADE propagates parent row deletion automatically down to dependent child tuples to preserve referential integrity.
[HI] पेरेंट टेबल से कोई पंक्ति डिलीट करने पर उससे जुड़ी चाइल्ड टेबल की सभी संबंधित पंक्तियाँ स्वतः डिलीट हो जाती हैं।
Q14. In ANSI SQL, which DDL statement creates an empty table without copying rows using CREATE TABLE ... AS SELECT?
(CREATE TABLE NewT AS SELECT * FROM OldT का उपयोग कर केवल संरचना कॉपी करने (बिना एक भी रो लाए) की मानक युक्ति क्या है?)
(A) Append TRUNCATE INSIDE SELECT
(B) Use SELECT NULL FROM OldT
(C) Replace AS with WITHOUT DATA ONLY in MySQL
(D) Append WHERE 1 = 0 so zero rows match the SELECT predicate
Correct Answer: (D)
[EN] Adding an always-false filter like WHERE 1 = 0 copies column definitions while inserting zero tuples.
[HI] अंत में WHERE 1 = 0 (हमेशा असत्य शर्त) जोड़ने से केवल खाली कॉलम संरचना कॉपी होती है और एक भी पंक्ति नहीं आती।
Q15. Which dialect difference is accurate when renaming or modifying a column in ALTER TABLE?
(ALTER TABLE द्वारा कॉलम का टाइप या परिभाषा बदलने के सिंटैक्स में कौन सा अंतर सही है?)
(A) All SQL engines forbid changing column widths once created
(B) SQL Server uses CREATE COLUMN to modify types
(C) MySQL and Oracle use MODIFY (or MODIFY COLUMN), whereas PostgreSQL and SQL Server use ALTER COLUMN
(D) PostgreSQL uses UPDATE COLUMN while MySQL uses DROP ADD
Correct Answer: (C)
[EN] MySQL/Oracle accept ALTER TABLE T MODIFY col new_type; PostgreSQL uses ALTER TABLE T ALTER COLUMN col TYPE new_type; SQL Server uses ALTER TABLE T ALTER COLUMN col new_type.
[HI] MySQL व Oracle में MODIFY प्रयुक्त होता है, जबकि PostgreSQL और SQL Server में ALTER COLUMN कीवर्ड प्रयुक्त होता है।
Q16. What happens to indexes and permissions attached to table Sales after running DROP TABLE Sales?
(DROP TABLE Sales चलाने के बाद Sales टेबल से जुड़े इंडेक्स और यूजर अनुमतियों (Permissions) का क्या होता है?)
(A) User privileges remain active even after recreation
(B) Only row data drops while indexes keep querying old values
(C) All indexes, triggers, constraints, and object-level privileges on Sales are permanently dropped too
(D) Indexes stay orphaned and attach to the next created table
Correct Answer: (C)
[EN] Dropping a table removes the entire table definition and every dependent index, trigger, constraint, and privilege binding in the catalog.
[HI] DROP TABLE करते ही उस टेबल से जुड़े सभी इंडेक्स, ट्रिगर, कंस्ट्रेंट्स और यूजर अधिकार भी पूरी तरह समाप्त हो जाते हैं।
Q17. Within SQL DDL Commands: CREATE TABLE, ALTER TABLE, DROP TABLE, TRUNCATE, which ddl command directly maps to: "Allocates new table schema, columns, and integrity constraints"?
(SQL DDL Commands: CREATE TABLE, ALTER TABLE, DROP TABLE, TRUNCATE में कौन सा DDL Command सीधे "Allocates new table schema, columns, and integrity constraints" से संबंधित है?)
(A) ALTER TABLE
(B) DROP TABLE
(C) CREATE TABLE
(D) TRUNCATE TABLE
Correct Answer: (C)
[EN] In SQL DDL Commands: CREATE TABLE, ALTER TABLE, DROP TABLE, TRUNCATE, 'CREATE TABLE' handles 'Allocates new table schema, columns, and integrity constraints' (Adds metadata to System Catalog; auto-commits in MySQL/Oracle).
[HI] SQL DDL Commands: CREATE TABLE, ALTER TABLE, DROP TABLE, TRUNCATE में 'CREATE TABLE' का कार्य/विवरण 'Allocates new table schema, columns, and integrity constraints' (Adds metadata to System Catalog; auto-commits in MySQL/Oracle) है।
Q18. Which option accurately describes 'ALTER TABLE' in SQL DDL Commands: CREATE TABLE, ALTER TABLE, DROP TABLE, TRUNCATE?
(SQL DDL Commands: CREATE TABLE, ALTER TABLE, DROP TABLE, TRUNCATE के संदर्भ में 'ALTER TABLE' की सही विशेषता कौन सी है?)
(A) Erases all rows, indexes, triggers, and schema definition
(B) Allocates new table schema, columns, and integrity constraints
(C) Adds, drops, renames, or modifies columns and constraints
(D) Deallocates all data pages and resets identity counter to seed
Correct Answer: (C)
[EN] 'ALTER TABLE' provides 'Adds, drops, renames, or modifies columns and constraints' — key point: Retains existing row data while updating table definition.
[HI] 'ALTER TABLE' का मुख्य विवरण 'Adds, drops, renames, or modifies columns and constraints' है (Retains existing row data while updating table definition)।
Q19. In SQL DDL Commands: CREATE TABLE, ALTER TABLE, DROP TABLE, TRUNCATE, identify the correct parameter for the specification: "Deallocates all data pages and resets identity counter to seed".
(SQL DDL Commands: CREATE TABLE, ALTER TABLE, DROP TABLE, TRUNCATE में "Deallocates all data pages and resets identity counter to seed" विवरण किस विकल्प के लिए सही है?)
(A) TRUNCATE TABLE
(B) DROP TABLE
(C) ALTER TABLE
(D) CREATE TABLE
Correct Answer: (A)
[EN] 'TRUNCATE TABLE' corresponds to 'Deallocates all data pages and resets identity counter to seed' (DDL bulk removal without WHERE; preserves empty table structure).
[HI] 'TRUNCATE TABLE' का संबंध 'Deallocates all data pages and resets identity counter to seed' (DDL bulk removal without WHERE; preserves empty table structure) से है।
Q20. Considering SQL DDL Commands: CREATE TABLE, ALTER TABLE, DROP TABLE, TRUNCATE, what key behavior defines 'DROP TABLE'?
(SQL DDL Commands: CREATE TABLE, ALTER TABLE, DROP TABLE, TRUNCATE में 'DROP TABLE' की मुख्य भूमिका या मान क्या है?)
(A) Adds, drops, renames, or modifies columns and constraints
(B) Deallocates all data pages and resets identity counter to seed
(C) Allocates new table schema, columns, and integrity constraints
(D) Erases all rows, indexes, triggers, and schema definition
Correct Answer: (D)
[EN] 'DROP TABLE' represents 'Erases all rows, indexes, triggers, and schema definition' (Removes object entry from catalog; table must be recreated).
[HI] 'DROP TABLE' का अर्थ/मान 'Erases all rows, indexes, triggers, and schema definition' है (Removes object entry from catalog; table must be recreated)।
SQL DDL Commands: CREATE TABLE, ALTER TABLE, DROP TABLE, TRUNCATE — Exam FAQs
Q1: Can I recover a table dropped via DROP TABLE using a simple ROLLBACK?
क्या DROP TABLE से हटाई गई टेबल को साधारण ROLLBACK कमांड से वापस लाया जा सकता है?
[EN] In MySQL and Oracle, no—DDL triggers an implicit commit, so only backups/flashback recovery can restore it. In PostgreSQL or SQL Server, if DROP TABLE ran inside an unclosed BEGIN transaction, ROLLBACK can restore it.
[HI] MySQL व Oracle में नहीं—क्योंकि DDL स्वतः कमिट कर देता है (केवल बैकअप/फ्लैशबैक से वापसी संभव है)। पर PostgreSQL या SQL Server में यदि यह BEGIN ट्रांज़ैक्शन के भीतर है तो ROLLBACK से बच सकता है।
Q2: If TRUNCATE deletes all rows, why keep both TRUNCATE and DROP?
जब TRUNCATE से सारा डेटा उड़ जाता है, तो TRUNCATE और DROP दोनों अलग कमांड क्यों हैं?
[EN] TRUNCATE preserves the table schema, column types, indexes, and grants so you can immediately reload fresh rows (ideal for staging tables), whereas DROP destroys the table object entirely.
[HI] TRUNCATE में टेबल ढांचा, कॉलम, इंडेक्स व अधिकार सुरक्षित रहते हैं जिससे तुरंत नया डेटा लोड किया जा सकता है, जबकि DROP पूरी टेबल का अस्तित्व ही मिटा देता है।
Q3: Does ALTER TABLE lock the table against concurrent writes?
क्या ALTER TABLE चलते समय टेबल पर लॉक लगता है?
[EN] Schema changes acquire an exclusive metadata/table lock at least briefly; modern engines support online/instant DDL for simple operations (like adding nullable columns), whereas type changes may rewrite the table.
[HI] हाँ, स्कीमा बदलाव के दौरान मेटाडेटा लॉक लगता है; आधुनिक DBMS में साधारण बदलाव (जैसे नलेबल कॉलम जोड़ना) तेज़ी से ऑनलाइन हो जाते हैं, पर डेटा टाइप बदलने पर पूरी टेबल रीराइट हो सकती है।
Post a Comment
Post a Comment