[Link] is the primary key?
A primary key is a unique identifier for each record in a table.
It never allows duplicates or null values.
[Link] we put more than one primary key in table?
No. A table can have only one primary key, but that primary key can contain
multiple columns (composite key).
[Link] it possible to drop primary key?
Yes, we can drop the primary key using the DROP PRIMARY KEY command.
[Link] key delete code?
ALTER TABLE table_name
DROP PRIMARY KEY;
___________________________________________________________________________________
_______
[Link] is the foreign key?
A foreign key is a column that links one table to another by referencing the
primary key of the other table.
[Link] it possible to delete data from parebt table if the data is existing in child
table?
No, you cannot delete data from the parent table if it is already referenced in the
child table.
It will throw a foreign-key constraint error unless ON DELETE CASCADE is used.
[Link] else if we want to delete the data from parent table that is the
existing in child table?
Yes. First delete the matching rows from the child table.
Then only you can delete the parent row.
___________________________________________________________________________________
_______
[Link] me about joins?
Joins are used to combine rows from two tables using a matching column.”
Short types:
INNER JOIN: Match irukura rows mattum.
LEFT JOIN: Left table full + match irundha right.
RIGHT JOIN: Right table full + match irundha left.
FULL JOIN: Rendu table full + matches.
[Link] is the inner joint?
Inner Join = Only the matching rows from both tables.
[Link],right,full?
Left Outer Join:
“Left join shows all rows from the left table and only the matching rows from the
right table.”
Right Outer Join:
“Right join shows all rows from the right table and only the matching rows from the
left table.”
Joining 3 tables:
“Yes. We can join three or more tables using multiple join conditions.”
Full Outer Join:
“Full join shows all rows from both tables, including non-matching rows.”
___________________________________________________________________________________
____
what is dual?
Dual = Dummy table in Oracle.
Dual is a single-row, single-column dummy table used to run functions or
expressions without using a real table.
___________________________________________________________________________________
____
tell me the aggragate functions!
Aggregate functions (main 5):
SUM()
AVG()
COUNT()
MAX()
MIN()
what is the command of find the total salary in table?
id name salary
1 Ravi 10000
2 Kumar 15000
3 Ajay 20000
SELECT SUM(salary) FROM employees;
Output:
45000
___________________________________________________________________________________
_____
[Link] is the diff between whwere and having?
WHERE ? filter before grouping.
HAVING ? filter after grouping.
One line:
WHERE filters rows; HAVING filters groups.
[Link] is the diff betweendelete and trunk ?
DELETE ? row by row delete, slow, can rollback.
TRUNCATE ? whole table clear, fast, cannot rollback.
One line:
DELETE = row delete; TRUNCATE = full table wipe.
[Link] it delete we can delete the all records?
DELETE can remove all records if you don’t use a WHERE condition.
DELETE FROM table_name;
“Yes, DELETE can delete all rows.
[Link] to find a secound maximum salary in a table?
Table: employees
id name salary
1 A 20000
2 B 30000
3 C 40000
4 D 50000
SELECT MAX(salary)
FROM employees
WHERE salary < (SELECT MAX(salary) FROM employees);
Step 1:
(SELECT MAX(salary) FROM employees)
? Table la irukra biggest salary find pannum.
? Example: 50000.
Step 2:
WHERE salary < 50000
? Biggest salary-ah thalli, athuku keela iruka salaries mattum filter pannum.
? 20000, 30000, 40000.
Step 3:
SELECT MAX(salary)
? Filter pannina list la irukra biggest value edukkum.
? 40000.
Final result:
40000 = second highest.
[Link], i want to display the maximum slaray,those who have greter than 80,000?
SELECT MAX(salary)
FROM employees
WHERE salary > 80000;
___________________________________________________________________________________
_
[Link] is between char and var?
CHAR ? Fixed length. Space waste. Fast.
VARCHAR ? Variable length. No space waste. Flexible.
___________________________________________________________________________________
__
[Link] is the constraint in sql?
Constraints are rules used to control and protect data in a table.”
Simple list:
PRIMARY KEY
FOREIGN KEY
UNIQUE
NOT NULL
CHECK
DEFAULT
[Link] is the primary key constarints in sql?
PRIMARY KEY
?Duplicate + NULL allow panna koodadhu.
Yen: Row-oda unique identity thevai.
[Link] is the composite key?
Composite Key = Two or more columns together acting as a Primary Key.
Composite key means multiple columns used to uniquely identify a row.
[Link] take null values?
No. Composite key cannot take NULL values.
Reason:
Composite key = Primary key group.
Primary key ? NULL allow panna koodadhu.
___________________________________________________________________________________
___
what is distinct in sql?
DISTINCT = Duplicate remove pannura keyword.
One line:
“DISTINCT shows only unique values.
___________________________________________________________________________________
____
[Link] is the set operator in sql?
Set operators = Two query result-ah join panna use pannura operators.
Main 4:
UNION ? Merge + remove duplicates
UNION ALL ? Merge + keep duplicates
INTERSECT ? Common rows only
MINUS ? First query la irundhu second la illa rows
[Link] is the intercst operator
It takes result from Query 1.
It takes result from Query 2.
It compares both.
It shows only the rows that are present in both results.
One line:
“INTERSECT shows only the common rows between two queries.”
[Link] is minus operator?
MINUS shows the rows that are in the first query but NOT in the second query.”
Example:
Query1: A, B, C
Query2: B, C
MINUS result ? A
(Only in first, not in second)
[Link] is union?
UNION joins two query results and removes duplicate rows.
[Link] is union all?
UNION ALL joins two query results and does NOT remove duplicates.
___________________________________________________________________________________
______
[Link] is the row id adn row num in sql?
ROWID:
Physical address of the row in the table.
Shows where the row is stored in memory.
Unique and fixed for that row.
ROWNUM:
Temporary number given to rows after selecting.
Starts from 1,2,3…
[Link] id take physical space?
Yes.
ROWID takes physical space because it is part of the row’s physical storage
information.
[Link] is dw between replace and traslate in sql?
REPLACE – Full word/part change
It changes a full piece of text.
Not character-by-character.
Example:
"APPLE"
REPLACE('APPLE', 'PP', 'XX') ? AXXLE
(Full “PP” replace aagudhu)
TRANSLATE – Letter by letter change
It changes each character separately.
Mapping madhiri work aagum.
Example:
"ABC"
TRANSLATE('ABC', 'ABC', '123') ? 123
(A?1, B?2, C?3)
[Link] is nvl function in sql?
NVL function = Replace NULL with a value.
SELECT name, NVL(bonus, 0) AS final_bonus
FROM employees;
NVL looks for NULL. If NULL, it returns 0. Otherwise, it returns the original
value.
[Link] syntax and working?
It takes all the values in that column.
Adds them together.
Divides by the total number of rows (except NULL).
Result = average.
SELECT AVG(salary) AS average_salary
FROM employees;
[Link] to fetch nth number record?
SELECT *
FROM (
SELECT t.*, ROW_NUMBER() OVER (ORDER BY id) AS rn
FROM employees t
)
WHERE rn = 5;
[Link] id from table?
program:-
SELECT id, COUNT(id) AS count_id
FROM employees
GROUP BY id
HAVING COUNT(id) > 1;
Example Table (employees)
id name
1 A
2 B
2 C
3 D
3 E
3 F
?? What happens when we run the query?
Step 1: GROUP BY id
SQL groups same id values together:
id 1 ? group: [1]
id 2 ? group: [2, 2]
id 3 ? group: [3, 3, 3]
Step 2: COUNT(id)
Count inside each group:
id 1 ? count = 1
id 2 ? count = 2
id 3 ? count = 3
Step 3: HAVING COUNT(id) > 1
Show only IDs whose count is more than 1 (duplicates):
id 1 ? 1 (NO)
id 2 ? 2 (YES ? duplicate)
id 3 ? 3 (YES ? duplicate)
?? Final Output:
id count_id
2 2
3 3
_________________________________________________________________________________
[Link] is database?
Database is a storage system that keeps data safe and easy to access.
Example: tables, rows, columns.
[Link] you can relationhip between the table?
Relationship is made by connecting one table’s primary key to another table’s
foreign key.
[Link] you can create a table in database?
You can create a table using CREATE TABLE command.
CREATE TABLE employees (
id NUMBER,
name VARCHAR2(50),
salary NUMBER
);
[Link] is data?
Data = Information.
Data means raw facts like numbers, names, and details.
[Link] is the index?
Index is Speeds up searching in a table.
Works like a book index ? fast to find data.
One line:
“Index = fast search tool.”
6. what is the Unique Index
Same as index, but no duplicate values allowed in that column.
Ensures each value is unique.
___________________________________________________________________________________
__
[Link] many commands in sql?
DDL – Data Definition Language
Table structure create / change / delete.
Commands:
CREATE ? create table
ALTER ? change table
DROP ? delete table
TRUNCATE ? remove all rows
RENAME ? rename table
One line:
“DDL changes the structure of database.”
1.2 DML (Data Manipulation Language)
Definition:
“Commands used to add, edit, or delete data inside the table.”
Simple:
It works on the actual data.
Commands: INSERT, UPDATE, DELETE
1.3 DQL (Data Query Language)
Definition:
“Commands used to read or fetch data from the table.”
Simple:
It is only for viewing data.
Command: SELECT
1.4 DCL (Data Control Language)
Definition:
“Commands used to give or remove access to users.”
Simple:
It controls who can do what.
Commands: GRANT, REVOKE
1.5 Definition: TCL(Transaction control language):-
“Commands used to save or undo changes in the database.”
Simple:
It controls transactions (commit or rollback).
Commands: COMMIT, ROLLBACK, SAVEPOINT
[Link] you can retrive allthe coloums from all the rows fromt he table?
Use SELECT * to get all columns and all rows.
Query:
SELECT * FROM table_name;
[Link] you can alter some data in the table?
To change data inside a table, use UPDATE.
Query:
UPDATE table_name
SET column_name = new_value
WHERE condition;
_______________________________________________________________________________
[Link] is the subquery?
Subquery = a query inside another query.
It helps to get one result first, then use that result in the main query.
One line:
“Subquery means using one SELECT inside another SELECT.”
[Link] is diff between ordee clause and having clause
ORDER BY
Used to sort the result (ASC/DESC).
Works after selecting rows.
One line:
“ORDER BY = sort the output.”
HAVING
Used to filter groups after GROUP BY.
Works after grouping.
___________________________________________________________________________________
_