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 17

To attach tags to a question in Eloquent M:N
$question->tags()->attach($tagIds)
click to copy
To remove all tag associations from a question in Eloquent M:N
$question->tags()->detach()
click to copy
$question->tags()->sync($newTagIds) in Eloquent
Adds new tags and removes old ones so the relationship matches exactly $newTagIds
click to copy
Which Eloquent method creates a model AND saves it to database in one step
Question::create(['question'=>'...'])
click to copy
Question::firstOrCreate(['question'=>'Test?'],['option_a'=>'A']) does
Finds first matching row or creates it if not found
click to copy
Question::updateOrCreate(['id'=>1],['q_level'=>3]) does
Updates if found by first arg, creates if not found
click to copy
Which prevents concurrent duplicate inserts in Laravel
Unique database constraint + try-catch for IntegrityConstraintViolationException
click to copy
Database connection pooling improves
Performance by reusing existing connections instead of creating new ones for each request
click to copy
Which Laravel config file sets database connection settings
config/database.php (reads from .env variables)
click to copy
DB_CONNECTION=mysql in .env sets
The database driver (mysql, pgsql, sqlite, sqlsrv)
click to copy
To add a new column 'marks' INT DEFAULT 0 to existing questions table in Laravel migration
Schema::table('questions', function(Blueprint $t){ $t->integer('marks')->default(0); })
click to copy
$table->after('solution') in migration column definition
Places the new column AFTER the solution column in the table structure
click to copy
$table->change() in migration is used to
Rename table
click to copy
Which SQL command shows FK constraints on questions table in MySQL
SELECT * FROM information_schema.KEY_COLUMN_USAGE WHERE TABLE_NAME='questions'
click to copy
To safely drop a column that might not exist in migration
Schema::table('questions',fn($t)=>$t->dropColumn('old_col')) in a try-catch or use Schema::hasColumn() check first
click to copy
Which is the correct way to handle database errors in Laravel
Catch Illuminate\\Database\\QueryException for DB errors
click to copy
Which PHP/Laravel code correctly inserts a question matching the screenshot table format
Both A and C are correct
click to copy

DBMS → SQL Basics 1

Which SQL query most efficiently counts questions per q_level without NULL q_level
SELECT q_level,COUNT(*) FROM questions WHERE q_level IS NOT NULL GROUP BY q_level
click to copy

DBMS → Relational Model 1

To add a foreign key constraint to existing questions.assignment_id column in migration
$table->foreign('assignment_id')->references('id')->on('assignments')->onDelete('cascade')
click to copy

DBMS → Transactions 3

DB::transaction(function(){ /* multiple inserts */ }) advantage
Ensures all inserts succeed or all fail atomically - no partial data
click to copy
DB::table('questions')->lockForUpdate() in a transaction
Acquires an exclusive lock preventing other transactions from reading/writing these rows
click to copy
DB::table('questions')->sharedLock() in a transaction
Acquires a shared lock allowing reads but preventing exclusive locks from other transactions
click to copy