Thanks to visit codestin.com
Credit goes to www.scribd.com

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

SQL Queries

The document provides a comprehensive overview of MySQL, including definitions of key concepts such as databases, tables, and rows, along with their syntax and examples. It also details common queries like SELECT, INSERT, UPDATE, and DELETE, as well as constraints like NOT NULL, UNIQUE, and PRIMARY KEY. Additionally, it covers important keywords and clauses used in SQL statements, offering a clear reference for MySQL operations.

Uploaded by

pavankolla1020
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)
3 views3 pages

SQL Queries

The document provides a comprehensive overview of MySQL, including definitions of key concepts such as databases, tables, and rows, along with their syntax and examples. It also details common queries like SELECT, INSERT, UPDATE, and DELETE, as well as constraints like NOT NULL, UNIQUE, and PRIMARY KEY. Additionally, it covers important keywords and clauses used in SQL statements, offering a clear reference for MySQL operations.

Uploaded by

pavankolla1020
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/ 3

Okay, here's a list of common MySQL definitions, queries, constraints, keywords, and clauses

with a one-line definition, syntax, and example for each:


Definitions:
Definition One-Line Definition Syntax Example
Database An organized collection CREATE DATABASE CREATE DATABASE
of data. database_name; my_database;
Table A structure within a CREATE TABLE CREATE TABLE users
database to hold table_name (...); (id INT, name
related data. VARCHAR(50));
Column A set of data values of column_name name VARCHAR(50)
a particular simple type. data_type [constraints]
Row (Record) A set of related data (value1, value2, ...) (1, 'John Doe')
values.
Queries:
Query One-Line Definition Syntax Example
SELECT Retrieves data from SELECT column1, SELECT name, age
one or more tables. column2 FROM FROM users;
table_name;
INSERT Adds new rows of data INSERT INTO INSERT INTO users
into a table. table_name (columns) (name, age) VALUES
VALUES (values); ('Jane', 30);
UPDATE Modifies existing UPDATE table_name UPDATE users SET
records in a table. SET column = value age = 31 WHERE
WHERE condition; name = 'Jane';
DELETE Removes rows from a DELETE FROM DELETE FROM users
table. table_name WHERE WHERE id = 1;
condition;
Constraints:
Constraint One-Line Definition Syntax within CREATE Example
TABLE
NOT NULL Ensures that a column column_name name VARCHAR(50)
cannot have a NULL data_type NOT NULL NOT NULL
value.
UNIQUE Ensures that all values column_name email VARCHAR(100)
in a column are data_type UNIQUE UNIQUE
different.
PRIMARY KEY Uniquely identifies each PRIMARY KEY id INT PRIMARY KEY
row in a table; must be (column_name)
NOT NULL.
FOREIGN KEY Establishes a link FOREIGN KEY FOREIGN KEY
between data in two (fk_column) (user_id)
tables. REFERENCES REFERENCES
other_table(pk_column) users(id)
CHECK Ensures that all values CHECK (condition) age INT CHECK (age
in a column satisfy a >= 18)
condition.
Constraint One-Line Definition Syntax within CREATE Example
TABLE
DEFAULT Sets a default value for column_name is_active BOOLEAN
a column if no value is data_type DEFAULT DEFAULT TRUE
specified. value
Keywords:
Keyword One-Line Definition Syntax Usage Example
SELECT Specifies the columns SELECT column1, ... SELECT * FROM
to retrieve. FROM ... products;
FROM Specifies the table(s) to SELECT ... FROM SELECT name FROM
retrieve data from. table_name users;
WHERE Filters records based SELECT ... FROM ... SELECT * FROM
on specified conditions. WHERE condition orders WHERE
order_date >
'2024-01-01';
ORDER BY Sorts the result set. `SELECT ... FROM ... DESC]`
ORDER BY column
[ASC
LIMIT Restricts the number of SELECT ... FROM ... SELECT * FROM
rows to retrieve. LIMIT count products LIMIT 10;
AND, OR Logical operators to WHERE condition1 WHERE age > 25 AND
combine conditions. AND/OR condition2 city = 'New York';
NOT Negates a condition. WHERE NOT condition WHERE NOT status =
'inactive';
NULL Represents a missing WHERE column IS WHERE email IS
or unknown value. NULL or WHERE NULL;
column IS NOT NULL
AS Renames a column or column_name AS SELECT product_name
table alias. alias_name AS item FROM
products;
JOIN Combines rows from table1 JOIN table2 ON SELECT orders.id,
two or more tables. condition users.name FROM
orders JOIN users ON
orders.user_id =
users.id;
Clauses:
Clause One-Line Definition Syntax Usage within Example
SELECT statements
WHERE Filters rows based on a SELECT ... FROM ... SELECT * FROM
condition. WHERE condition products WHERE price
> 50;
GROUP BY Groups rows that have SELECT column(s) SELECT department,
the same values in FROM ... WHERE ... COUNT(*) FROM
specified columns. GROUP BY column(s) employees GROUP BY
department;
HAVING Filters groups based on SELECT ... FROM ... SELECT department,
Clause One-Line Definition Syntax Usage within Example
SELECT statements
a specified condition. GROUP BY ... HAVING COUNT(*) FROM
condition employees GROUP BY
department HAVING
COUNT(*) > 5;
ORDER BY Sorts the result set. `SELECT ... FROM ... DESC]`
ORDER BY column(s)
[ASC
LIMIT Restricts the number of SELECT ... FROM ... SELECT * FROM
rows returned. LIMIT [offset,] count books LIMIT 5;
Let me know if you'd like more details or examples for any of these!

You might also like