Which SQL command removes all rows from a table but keeps the table structure?
Solution
TRUNCATE removes all rows quickly; DROP removes the table itself.
20 technical questions of moderate difficulty, as asked in campus placement and company tests. Each has a short explanation.
Which SQL command removes all rows from a table but keeps the table structure?
TRUNCATE removes all rows quickly; DROP removes the table itself.
Which normal form removes partial dependencies?
2NF requires every non-key attribute to depend on the whole primary key.
Which normal form removes transitive dependencies?
3NF requires non-key attributes to depend only on the key, not on other non-key attributes.
What does the 'A' in ACID stand for?
ACID: Atomicity, Consistency, Isolation, Durability.
Which key uniquely identifies each row in a table and cannot be NULL?
A primary key is unique and NOT NULL.
A foreign key is used to:
A foreign key enforces referential integrity between tables.
What does this query return?
CREATE TABLE emp(name TEXT, salary INT);
INSERT INTO emp VALUES ('Asha', 50000), ('Ravi', 45000), ('Meena', 30000);
SELECT COUNT(*) FROM emp WHERE salary > 40000;Two employees (Asha and Ravi) earn more than 40000.
What does this query return?
CREATE TABLE emp(name TEXT, dept TEXT);
INSERT INTO emp VALUES ('A','IT'), ('B','IT'), ('C','HR');
SELECT dept, COUNT(*) FROM emp GROUP BY dept HAVING COUNT(*) > 1;Grouping by department, IT has 2 employees, which is the only group with more than one.
Which clause filters groups after GROUP BY?
WHERE filters rows before grouping; HAVING filters groups after.
Which join returns all rows from the left table and matching rows from the right table?
A LEFT JOIN keeps every left row, with NULLs where there is no match.
What does this query return?
CREATE TABLE emp(name TEXT, salary INT);
INSERT INTO emp VALUES ('Asha', 50000), ('Ravi', 45000), ('Meena', 30000);
SELECT MAX(salary) FROM emp WHERE salary < (SELECT MAX(salary) FROM emp);The second highest salary is the highest salary below the maximum: 45000.
Which SQL keyword removes duplicate rows from a result?
SELECT DISTINCT returns only unique rows.
Which of these is a DDL (Data Definition Language) command?
DDL defines structure: CREATE, ALTER, DROP, TRUNCATE.
Which of these is a DML (Data Manipulation Language) command?
DML changes data: INSERT, UPDATE, DELETE.
What does COMMIT do in a transaction?
COMMIT saves the transaction's changes; ROLLBACK undoes them.
In an ER diagram, a relationship where one row of A relates to many rows of B is:
One department has many employees: one-to-many.
What does this query return?
CREATE TABLE c(id INT, name TEXT); CREATE TABLE o(oid INT, cid INT); INSERT INTO c VALUES (1,'A'), (2,'B'); INSERT INTO o VALUES (1,1), (2,1), (3,2); SELECT COUNT(*) FROM c JOIN o ON c.id = o.cid;
An INNER JOIN on matching ids gives three rows: orders 1, 2 and 3 all have customers.
Which aggregate function ignores NULL values?
COUNT(column), SUM, AVG, MIN and MAX all skip NULLs; only COUNT(*) counts every row.
An index on a column mainly helps to:
An index allows faster lookups at the cost of extra storage and slower writes.
Which property ensures that once a transaction commits, its changes survive a crash?
Durability guarantees committed data is not lost.
Want guided preparation? Placement Papers Prep courses by Dr. Kiran Derle, with video lessons and full-length mocks.
See placement courses ↗