Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2 views

MySQL Document

Uploaded by

siva kick
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

MySQL Document

Uploaded by

siva kick
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

MYSQL INTERVIEW QUESTIONS

Why should we use MySQL?

• Fast, reliable, and easy to use.


• Protects sensitive data from intruders.
• Scalable and can handle huge amount of data.
• Compatible with almost every OS>

Order of MySQL Query execution?

• From & Joins


• Where ➔ Filter the base data
• Group by ➔Aggregate
• Having ➔ Filter aggregate data
• Select ➔returns final data
• Order by ➔sorts final data(asc & desc)
• Limit ➔ limits returned data to a row count

JOINS:

INNER JOINS:

It selects all rows from both the tables as long as the condition satisfies.

LEFT JOINS:
The joins returns all the rows of the table on the left side of the join and matching rows for the table
on the right side of join.

RIGHT JOINS:

The joins returns all the rows of the table on the right side of the join and matching rows for the
table on the left side of join.

FULL JOINS:
It selects both the LEFT JOIN and RIGHT JOIN.

4.How many triggers are allowed In MySQL table?

• BEFORE INSERT
• AFTER INSERT
• BEFORE UPDATE
• AFTER UPDATE
• BEFORE DELETE
• AFTER DELETE
UNION:

• Combines returns from multiple SELECT Queries.


• Returns all distinct rows.

UNION ALL:
Returns all rows from the tables meeting the Query.

MINUS:
Returns all di.stinct rows selected by first query but not second query.

INTERSECT:
Intersection of both the queries.

DELETE:
• Delete command is used to delete a row in a table.
• You can rollback data after using delete statement.
• It is a DML command.
• It is a slower than truncate.

TRUNCATE:

• Truncate is used to delete all the rows from the table.


• You cannot rollback data.
• It is DDL command.
• It is faster.

CHAR:

• Stores data is fixed length format.


• Strings smaller than specified length and padded with space characters.
• Used in smaller data.
• Comparativelyfaster.

VARCHAR:

• Stores values in variable length.


• No padding of spaces
• Used to store large data
• Comparatively slow.

Data Manipulating language(DML):

• SELECT ➔ This is used to print the data.


• INSERT-➔ This key is used to insert the values.
• UPDATE ➔ This key is used to change the data.
• DELETE-➔ This key is used to delete the column.

Data Definition Language(DDL):


• CREATE: Used to create table.
• ALTER or RENAME : To change the table name.
• DROP: The table will be remove .
• TRUNCATE: It Is used to delete all the rows from the table.

Transcatlon Control Language (TCL):

• COMMIT: This key Is used In SQL by default.


• To remove this we can write the Query
• Set autocommlt=0;
• Rollback;

ROLLBACK:

This key Is used to get the data what we Insert.

CONSTRAINTS:

o NOT NULL
o CHECK
o DEFAULT
o PRIMARY KEY
o AUTO_INCREMENT
o UNIQUE
o INDEX
o ENUM
o FOREIGN KEY

1.NOTNULl:

All values In column-- ➔ non empty.

Ex: Create table employee(

ID Int NOT NULL,

EmpName Varchar(255) NOT NULL

);

ALTER TABLE Employee

MODIFY EmpName NOT NULL;

2.UNIQUE:
All values in column - ➔ different

Ex :ALTER TABLE EMPLOYEE


CREATE TABLE EMPLOYEE(

ID int NOT NULL,

Name varchar(255)

CONSTRAINTS id_c UNIQUE(ID)

);

3. PRIMARY KEY:

UNIQUE + NOT NULL

A table can have ONE Primary key, but can have MANY unique constraints.

Ex: Create Table Employee(

ID int NOT NULL,

Name varchar (255),

PRIMARY KEY(ID)

);

4. FOREIGN KEY:
To maintain integrity of data

Ex: Create table employee(

ID int NOT NULL,

name varchar (255),

Dep_id int,

PRIMARY KEY (ID),

FOREIGN KEY (Dep_id)

REFERENCES DEPARTMENT(Oep_ld

);

S.CHECK:

Ex: Create table employee(


ID int NOT NULL,
Age int,

CHECK {Age>= 23)

);

AUTO_INREMENT:

► If you want to increase the id by default without providing id value, we have to use
AUTO_INCREMENT

ENUM:

► It's a kind of varchar values, but it allows selected values only


► gender ENUM('male', 'female', 'others'),

Default:

► it will take some default value if you are not declared


► suppose nationality INDIA by default

INDEX:

► This constraint allows us to create and retrieve values from the table very quickly and easily.
An index can be created using one or more than one column.
► It assigns a ROWID for each row in that way they were inserted into the table
► CREATE INDEX idx_name ON gender (name);

Difference b/w where and having dause?


Where:
WHERE Clause is used to filter the records from the table or used while joining more t han one
table.

HAVING:

HAVING Clause is used to filter the rec.ords from the groups based on the given condition in the
HAVING Clause.

You might also like