Quick Revision

GK One-Line Question & Answer

15541+ short questions with short answers, covering every category and sub-category on the site — no long articles to scroll through. Good for a fast recap before an exam, or a few minutes of daily practice.

DBMS → Introduction to DBMS 38

Union rule for FDs is derived from which two axioms
Augmentation and Transitivity
click to copy
Decomposition rule for FDs is derived from
Reflexivity only
click to copy
Canonical cover has no extraneous attributes and no redundant FDs. Which algorithm finds it
Standard algorithm: remove extraneous attributes (left then right side), then remove redundant FDs
click to copy
To check if FD A→B is redundant in set F, compute
A+ without the FD A→B; if B∈A+ then A→B is redundant
click to copy
R(A,B,C,D,E) with FDs: AB→C, C→D, D→E, E→A. What is the closure AB+?
ABCDE
click to copy
Which query finds employees in BOTH department 10 AND department 20 (transferred)
SELECT empid FROM emp WHERE dept=10 INTERSECT SELECT empid FROM emp WHERE dept=20
click to copy
Which SQL deletes duplicate rows keeping only lowest id
DELETE FROM emp WHERE id NOT IN (SELECT MIN(id) FROM emp GROUP BY name,salary)
click to copy
Which query efficiently finds all questions with no answer set (right_answer_id IS NULL)
SELECT * FROM questions WHERE right_answer_id IS NULL
click to copy
To update q_level for all questions in assignment_id=1 to level 3
UPDATE questions SET q_level=3 WHERE assignment_id=1
click to copy
Which SQL finds questions that have all 5 options filled (option_e is not NULL)
SELECT * FROM questions WHERE option_e IS NOT NULL
click to copy
To soft-delete all questions for assignment_id=2 in Laravel
Question::where('assignment_id',2)->delete() with SoftDeletes trait
click to copy
To permanently delete soft-deleted questions in Laravel
Question::onlyTrashed()->forceDelete()
click to copy
To restore soft-deleted questions in Laravel
Question::onlyTrashed()->restore()
click to copy
In Laravel, Question::where('assignment_id',1)->get() vs Question::where('assignment_id',1)->first()
get() returns Collection of all matches; first() returns only the first matching model or NULL
click to copy
DB::table('questions')->value('question') returns
First question's text as a plain value (not Collection/model)
click to copy
DB::table('questions')->exists() returns
Boolean: TRUE if at least one row matches the query, FALSE otherwise
click to copy
DB::table('questions')->doesntExist() returns
Boolean: TRUE if NO rows match the query
click to copy
Question::withCount('options') in Laravel Eloquent
Adds options_count attribute with count of related options
click to copy
DB::table('questions')->orderByRaw('FIELD(q_level,3,2,1)')->get() in MySQL
Orders by custom field order: 3 first, then 2, then 1
click to copy
DB::table('questions')->selectRaw('COUNT(*) as total, AVG(q_level) as avg_level')->first()
Returns a stdClass with total count and average q_level
click to copy
To get questions grouped by q_level with count in Laravel
DB::table('questions')->groupBy('q_level')->selectRaw('q_level,COUNT(*) as cnt')->get()
click to copy
Which Laravel method chains multiple OR conditions cleanly
->where(function($q){ $q->where('a',1)->orWhere('b',2) }) for grouped OR
click to copy
Which SQL finds the n-th highest salary (n=3rd highest)
SELECT salary FROM emp ORDER BY salary DESC LIMIT 2,1
click to copy
Which SQL lists all tables with their row counts
SELECT TABLE_NAME, TABLE_ROWS FROM information_schema.TABLES WHERE TABLE_SCHEMA='dbname'
click to copy
EXPLAIN output 'type=ALL' in MySQL means
Full table scan - no index used (worst case for large tables)
click to copy
EXPLAIN output 'type=ref' in MySQL means
Non-unique index lookup - finds rows matching an index condition
click to copy
EXPLAIN output 'type=const' in MySQL means
Single row found via unique index or PK - fastest possible lookup
click to copy
Which SQL creates a composite index for queries filtering by assignment_id and q_level
CREATE INDEX idx ON questions(assignment_id,q_level)
click to copy
SELECT DISTINCT question_type FROM questions returns
Unique question_type values (one row per distinct type)
click to copy
To add assignment_id=3 and copy all questions from assignment 1 in SQL
INSERT INTO questions(assignment_id,...) SELECT 3,...FROM questions WHERE assignment_id=1
click to copy
TRUNCATE vs DELETE: which can be rolled back (in most databases)
DELETE can be rolled back (DML); TRUNCATE typically cannot (DDL in most databases)
click to copy
Which SQL gets all questions where solution contains the word 'DBMS'
SELECT * FROM questions WHERE solution LIKE '%DBMS%'
click to copy
DB::table('questions')->where('question','LIKE','%DBMS%')->get() generates
SELECT * FROM questions WHERE question LIKE '%DBMS%'
click to copy
To get paginated questions (page 3, 10 per page) in Laravel
DB::table('questions')->skip(20)->take(10)->get()
click to copy
Laravel Eloquent selectRaw('option_a as correct_answer') WHERE right_answer_id = 'option_a' uses
SELECT with alias
click to copy
To find questions where right_answer_id is not one of the standard options
SELECT * FROM questions WHERE right_answer_id NOT IN ('option_a','option_b','option_c','option_d','option_e')
click to copy
Which Laravel method returns the count of questions per assignment efficiently
DB::table('questions')->select('assignment_id',DB::raw('COUNT(*) as cnt'))->groupBy('assignment_id')->get()
click to copy
Which SQL verifies data integrity after bulk insert of questions
SELECT * FROM questions WHERE option_a IS NULL OR option_b IS NULL OR option_c IS NULL OR option_d IS NULL OR right_answer_id IS NULL
click to copy

DBMS → Relational Model 2

R(A,B,C,D,E) with above FDs. How many candidate keys are there
4 (AB, CB, DB, EB)
click to copy
R(A,B,C) FDs: A→B, B→C, C→A. All candidate keys are
A, B, and C (each determines all others)
click to copy