SQL Flashcards

(42 cards)

1
Q

Insert query

A

INSERT INTO employees (id, name, age, department, salary) VALUES (1, ‘John Doe’, 30, ‘IT’, 50000);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

UPDATE

A

UPDATE employees
SET salary = 55000
WHERE id = 1;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

DROP

A

DROP TABLE employees;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

CREATE query

A

CREATE TABLE employees (
id INT PRIMARY KEY,
name VARCHAR(100),
age INT,
department VARCHAR(50),
salary DECIMAL(10,2)
);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Join syntax

A

SELECT Customers.customer_id, Customers.first_name, Orders.item
FROM Customers
JOIN Orders
ON Customers.customer_id = Orders.customer_id

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

char vs varchar

A

char 255, varchar 65535

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

binary

A

stream of data in binary form

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

SQL vs MYSQL

A

SQL from microsoft, MYSQL from oracle

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

VARCHAR vs TEXT

A

name VARCHAR(255), – Stores up to 255 characters inline
description TEXT stores here and there,

Varchar best for indexing , and faster in search

for big text like description, comment text is best because of less search

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

decimal datatype with digits

A

DECIMAL(10,2)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

date datatypes

A

Data Type Description Example

DATE Stores only date (YYYY-MM-DD) ‘2025-03-07’

DATETIME Stores date & time (YYYY-MM-DD HH:MM:SS) ‘2025-03-07 14:30:00’

TIMESTAMP Similar to DATETIME, but auto-updates with time zone support Used for recording changes

TIME Stores only time (HH:MM:SS) ‘14:30:00’

YEAR Stores a year (YYYY) ‘2025’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Cross join possible combination

A

m*n

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Primary key syntax

A

CREATE TABLE Students (
student_id INT PRIMARY KEY, – Unique identifier for each student
name VARCHAR(50),
age INT,
class VARCHAR(10)
);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Foreign key syntax

A

CREATE TABLE Marks (
mark_id INT PRIMARY KEY, – Unique ID for each mark entry
student_id INT, – Foreign Key referring to Students table
subject VARCHAR(50),
marks INT,
FOREIGN KEY (student_id) REFERENCES Students(student_id) – Linking to Students table
);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Composite key syntax

A

CREATE TABLE Enrollments (
student_id INT,
course_id INT,
enrollment_date DATE,
PRIMARY KEY (student_id, course_id) – Composite Key (student_id + course_id)
);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Candidate Key and its syntax

A

CREATE TABLE Students (
student_id INT UNIQUE, – Candidate Key
email VARCHAR(100) UNIQUE, – Candidate Key
name VARCHAR(50),
PRIMARY KEY (student_id) – Only one is chosen as the Primary Key
);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

inno db engine

A

If primary key not declared mysql create its own column and asign as primary key by itself, Reason: Having primary key or unique key is mandatory in DBMS, But not compulsory to declare

18
Q

What field type foreign key can refer

A

Primary key, Unique ( Candidate key )

19
Q

super key as foreign key

A

CREATE TABLE Employees (
emp_id INT NOT NULL,
email VARCHAR(100) UNIQUE,
name VARCHAR(50),
UNIQUE (emp_id, email) – Super Key without Primary Key
);
CREATE TABLE Salaries (
salary_id INT PRIMARY KEY,
emp_ref_id INT,
emp_email VARCHAR(100),
FOREIGN KEY (emp_ref_id, emp_email) REFERENCES Employees(emp_id, email)
);

20
Q

CHECK

A

CREATE TABLE students (
student_id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(50) NOT NULL,
age INT CHECK (age >= 18),
email VARCHAR(100) UNIQUE
);

21
Q

AUTO_INCREMENT

A

We can insert manually but next row will start from manually entered value

22
Q

DDL Data Definition Language

A

CREATE Creates a new table/database
ALTER Modifies an existing table
DROP Deletes a table/database
TRUNCATE

23
Q

DML Data Manipulation Language

A

INSERT Adds new records
UPDATE Modifies existing records
DELETE

24
Q

DQL Data Query Language

25
DCL Data Control Language
GRANT Gives user access REVOKE Removes user access
26
DCL Data Control Language
GRANT SELECT, INSERT ON students TO 'user1'@'localhost';
27
TCL Transaction Control Language
COMMIT Saves changes permanently ROLLBACK Reverts changes SAVEPOINT Creates a checkpoint
28
AGGREGATE
COUNT() Counts rows COUNT(*) SUM() Adds values SUM(salary) AVG() Finds average AVG(salary) MAX() Finds max value MAX(age) MIN() Finds min value MIN(age)
29
groupby having orderby
GROUP BY Groups data by column HAVING Filters grouped data ORDER BY
30
Closure
A closure is created when a function is defined inside another function and it retains access to the outer function’s variables even after the outer function has finished executing.
31
Closure example
function outerFunction() { let count = 0; // `count` is inside outerFunction's scope function innerFunction() { count++; // innerFunction remembers `count` console.log(count); } return innerFunction; // Returning inner function } const myClosure = outerFunction(); // Outer function executes and returns `innerFunction` myClosure(); // 1 myClosure(); // 2 myClosure(); // 3
32
Hoisting
Variables declared with var are hoisted but not initialized. Their value is undefined until the assignment occurs.
33
Event loop
Promise, async await are used for asynchronous calls
34
java vs javascript
server vs client data type multi thread vs single thread OOPS vs scripting language JVM vs browser (node js) Object model vs Prototype model
35
Prototype
In JavaScript, prototypes are the mechanism by which objects inherit properties and methods from one another. Every JavaScript object has an internal link to another object called its prototype. Object.prototype.type = "abc"; Array.prototype.type = "abc"; var obj 1 = {} obj1._prototype_.add=function(){}; var obj2 = {}; obj2 has add
36
const
Value cannot be declared alone. It must be defined VM127:1 Uncaught SyntaxError: Missing initializer in const declaration const person = {name:"dsde"} can be done : person.name = "dqdqe" cannot be done : person = {name:"dsdewfewde"}
37
Memory of data
primitive - stack non primitive / functions - heap event loops - queue string - constant pool memory why because strings can be frequently recurring and they will get pointed to a common memory
38
mutable
obj1 = obj2 obj1.abc = "hello"; obj2.abc - has hello
39
mutable vs immutable
In JavaScript, mutability refers to whether a value can be changed after it is created. Mutable: Objects, arrays, and functions can be modified after creation. Immutable: Primitive values (like numbers, strings, and booleans) cannot be changed once assigned. Type Mutable? Example Objects ✅ Yes {} Arrays ✅ Yes [] Functions ✅ Yes function() {} Strings ❌ No "hello" Numbers ❌ No 42 Booleans ❌ No true / false
40
ES6
1. let / const 2. arrow 3. template literal 4. default params 5. destructuring(obj & arr) 6. spread and rest operator (...) 7.promises () 8. OOP 9. modules (import vs export) 10. Map and Set
41
arrow vs function
1. no arguments 2. syntax 3. this - difference 4. ES6 5. arrow cannot be used for constructor 6. hoisting not happen in arrow
42
Alter query
ALTER TABLE table_name ADD column_name datatype; ALTER TABLE table_name DROP COLUMN column_name; ALTER TABLE table_name RENAME COLUMN old_name to new_name; ALTER TABLE table_name ALTER COLUMN column_name datatype;