0% found this document useful (0 votes)
42 views4 pages

SQL Server by ThePhenomenal

This document provides an overview of SQL and MySQL commands. It defines SQL, DDL, DML and various SQL statements like SELECT, INSERT, UPDATE, DELETE. It describes syntax for queries using WHERE, ORDER BY, GROUP BY, TOP, DISTINCT clauses. It also covers operators like LIKE, IN, BETWEEN, AND and OR and provides examples of their usage in queries.

Uploaded by

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

SQL Server by ThePhenomenal

This document provides an overview of SQL and MySQL commands. It defines SQL, DDL, DML and various SQL statements like SELECT, INSERT, UPDATE, DELETE. It describes syntax for queries using WHERE, ORDER BY, GROUP BY, TOP, DISTINCT clauses. It also covers operators like LIKE, IN, BETWEEN, AND and OR and provides examples of their usage in queries.

Uploaded by

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

MySQL server 2k08

Introduction

- Definition of SQL:
o SQL stands for Structured Query Language, it`s used to access and modify information or
data from a database
- Definition of DDL : data definition language
o Create
 Create command Syntax for database
 CREATE DATABASE-name such as “CREATE DATABASE
Phenomenal”
o USE
 the use command Syntax
 USE DATABASE-name such as “USE DATABASE Phenomenal”
o ALTER
 The Alter command is used to modify the structure of table without deleting.
 We can use ADD and MODIFY command with ALTER command such
as
ALTER TABLE –NAME such as ALTER TABLE Students
ALTER COLUMN name TEXT
o DROP
 The drop command is used to remove the database object from DBMS, and
delete the table from the database
 DROP COMMANS syntax
o DROP DATABASE-name
DROP School
DROP TABLE table-name
DROP TABLE Student
- TRUNCATE TABLE
o The TRUNCATE TABLE command used to delete all the rows/records from the entire
table
the truncate command also removes the index from the column
 TRUNNCATE syntax
 TRUNNCATE TABLE table-name
- Definition of DML: Data Manipulation language, the DML statement include four main
commands
o SELECT:
 The SELECT command is used to retrieve data from tables
o INSERT
 The INSERT command is used to insert new data into tables
o UPDATE
 The UPDATE command is used to modify existing data in tables
o DELETE
 The DELETE command is used to remove existing records from tables
.
.

Written by: The Phenomenal One private property Stick to the Code
MySQL server 2k08

 The SQL SELECT Statement Syntax


o To select all column data from a table use the following line of command
 SELECT * FROM table-name;
o To select some columns data from a table use the following line of command
 SELECT Col1, Col2, Col3 FROM table-name
o The Syntax if WHERE in SELECT query:
 SELECT Col1, Col2, Col2 FROM table-name WHERE[“Condition”];
 The SQL INSERT Statement Syntax
o To insert data into a table use the following line of command
 INSERT INTO table-name (Col1,Col2…..ColN) VALUES (Val1, Val2,….ValN)
 The SQL UPDATE Statement Syntax
o To UPDATE a data in a table use the following line of command
 UPDATE table-name SET Col1=Val1, Col2=Val2, WHERE Condition
 The SQL DELETE Statement Syntax
o To remove data in a table use the following line of command
 DELETE FROM table-name WHERE Condition
 SQL ORDER BY
o Used to sort the records in ascending or descending order, based on on rot more columns
 SQL ORDER BY clause Syntax
 SELECT Col1, Col2 FROM table-name ORDER BY Col1 ASC
 SELECT Col1, Col2 FROM table-name ORDER BY Col1 DESC
 SQL GROUP BY
- Definition of GROUP BY: is used to return all records together with specified column and
perform aggregate function on one or more columns
o The syntax for GROUP BY clause
 SELECT Col1
aggregate_function(Col2) FROM table-name GROUP BY Col1
 The aggregate_function is a place holder for these functions (SUM,
AVG, COUNT, MAX, MIN) the aggregate function is performed on the
Col2 with group by col1 value
 SQL TOP Clause
- The definition of TOP clause: is used to return TOP number record from a table
o The top clause is used to specify the number of records to return
 The syntax for top clause
 SELECT TOP(top value as number) Col1, Col2 FROM table-name
 SELECT TOP(top value as number) * FROM table-name WHERE
CONDITION
 SQL DISTINCT
- The definition of DISTINCT: the SQL DISTINCT clause is used to remove duplicate records from
the result of SQL selected statement
o The SQL DISTINCT clause Syntax
 SELECT DISTINCT Col1, Col2 FROM table-name
.
.

Written by: The Phenomenal One private property Stick to the Code
MySQL server 2k08

.
 SQL OPERATORS
o SQL LIKE OPERATOR
o SQL IN OPERATOR
o SQL BETWEEN OPERATOR
o SQL AND / OR OPERATOR

 SQL LIKE OPERATOR


- The Definition of LIKE operator: the LIKE operator is used to return all rows from a table whose
column value match a specific pattern
o The LIKE operator is mostly used to search engine if we want to make box in website
then we use LIKE operator to display the search result
 The SQL LIKE Syntax
 SELECT Col1, Col2, FROM table-name WHERE Col1 LIKE ‘m%’
 SQL IN OPERATOR
- Definition of IN OPERATOR: the SQL IN operator is used to select column with more than one
value in WHERE condition
o The IN operator allows us to specify more than one value in WHERE condition
 The in operator Syntax
 SELECT Col1, Col2 FROM table-name WHERE Col1 IN
(val1,val2,val3)

CHAPTER 2
 The SQL AND, OR, NOT Operators
- The WHERE Clause can be combined with AND, OR , and NOT Operators
- The AND & OR operator are used to filter records based on more than one condition
o The AND operator display a record if all the conditions separated by AND is True
o The OR operator displays a record if any of the conditions separated with OR is
True
 AND Syntax
 SELECT Col1, Col2 … FROM table-name WHERE Condition1
AND Condition2 AND Condition3 …;
 OR Syntax
 SELECT Col1, Col2 … FROM table-name WHERE Condition1 OR
Condition2 OR Condition3 …;
 NOT Syntax
 SELECT Col1, Col2 … FROM table-name WHERE NOT
Condition;
 SQL BETWEEN Operator
- The BETWEEN operator selects values within a given range. The values can be numbers
text, or dates
o The BETWEEN operator is inclusive: begin and end values are included.
 BETWEEN Syntax

Written by: The Phenomenal One private property Stick to the Code
MySQL server 2k08

 SELECT Column-name FROM table-name WHERE Column-name


BETWEEN Val1 AND Val2;

Written by: The Phenomenal One private property Stick to the Code

You might also like