[Go to site: main page, start]

0% found this document useful (0 votes)
7 views3 pages

MySQL Definitions Syntax Examples

The document provides comprehensive notes for a MySQL interview, covering key concepts such as stored procedures, views, indexes, triggers, functions, primary keys, foreign keys, joins, subqueries, and transactions. Each concept includes a definition, syntax, and an example for clarity. These notes serve as a mock interview preparation resource for understanding MySQL functionalities.

Uploaded by

D H A R U N
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)
7 views3 pages

MySQL Definitions Syntax Examples

The document provides comprehensive notes for a MySQL interview, covering key concepts such as stored procedures, views, indexes, triggers, functions, primary keys, foreign keys, joins, subqueries, and transactions. Each concept includes a definition, syntax, and an example for clarity. These notes serve as a mock interview preparation resource for understanding MySQL functionalities.

Uploaded by

D H A R U N
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

MySQL Interview Notes – Definitions, Syntax &

Examples
Complete mock interview ready notes.

Stored Procedure
Definition: A stored procedure is a precompiled collection of SQL statements stored in the
database and executed by calling its name.

Syntax:
CREATE PROCEDURE procedure_name()
BEGIN
SQL statements;
END;

Example:
CREATE PROCEDURE GetEmployees()
BEGIN
SELECT * FROM employees;
END;

View
Definition: A view is a virtual table created using a SELECT query.

Syntax:
CREATE VIEW view_name AS SELECT columns FROM table;

Example:
CREATE VIEW high_salary AS
SELECT emp_name, salary FROM employees WHERE salary > 40000;

Index
Definition: An index is a database object that improves query performance.

Syntax:
CREATE INDEX index_name ON table(column);

Example:
CREATE INDEX idx_salary ON employees(salary);

Trigger
Definition: A trigger is an automatic action executed in response to table events.
Syntax:
CREATE TRIGGER trigger_name BEFORE|AFTER event ON table FOR EACH ROW statement;

Example:
CREATE TRIGGER before_insert_emp
BEFORE INSERT ON employees
FOR EACH ROW
SET [Link] = [Link] + 1000;

Function
Definition: A function is a database object that returns a single value.

Syntax:
CREATE FUNCTION function_name(params) RETURNS datatype RETURN expression;

Example:
CREATE FUNCTION annual_salary(sal INT)
RETURNS INT
RETURN sal * 12;

Primary Key
Definition: A primary key uniquely identifies each record in a table.

Syntax:
PRIMARY KEY(column_name)

Example:
emp_id INT PRIMARY KEY

Foreign Key
Definition: A foreign key establishes a relationship between two tables.

Syntax:
FOREIGN KEY(column) REFERENCES table(column)

Example:
FOREIGN KEY (dept_id) REFERENCES department(dept_id)

Join
Definition: A join combines rows from two or more tables.

Syntax:
SELECT columns FROM t1 JOIN t2 ON condition;
Example:
SELECT [Link], d.dept_name FROM employees e INNER JOIN department d ON e.dept_id
= d.dept_id;

Subquery
Definition: A subquery is a query inside another query.

Syntax:
SELECT column FROM table WHERE column = (SELECT column FROM table);

Example:
SELECT * FROM employees WHERE salary > (SELECT AVG(salary) FROM employees);

Transaction
Definition: A transaction is a set of SQL operations executed as a single unit.

Syntax:
START TRANSACTION; SQL statements; COMMIT;

Example:
START TRANSACTION;
UPDATE employees SET salary = salary + 1000;
COMMIT;

You might also like