Introduction
SQL can execute queries against a databaseWhat is SQL?
- SQL stands for Structured Query Language
What Can SQL do?
SQL can retrieve data from a database
SQL can insert records in a database
SQL can update records in a database
SQL can delete records from a database
SQL can create new databases
SQL can create new tables in a database
SQL can create stored procedures in a database
SQL can create views in a database
SQL can set permissions on tables, procedures, and views
Database Tables
A database most often contains one or more tables. Each table is identified by a name (e.g. "Student" or "Employee"). Tables contain records (rows) with data.>rows are also know as tuples.
Student ID Student name contact age
1 Ash 890 21
2 Anny 789 22
3 Stain 465 20
4 Harry 769 25
5 Dev 899 23
Some of The Most Important SQL Commands
UPDATE - updates data in a database
DELETE - deletes data from a database
INSERT INTO - inserts new data into a database
CREATE DATABASE - creates a new database
ALTER DATABASE - modifies a database
CREATE TABLE - creates a new table
ALTER TABLE - modifies a table
DROP TABLE - deletes a table
CREATE INDEX - creates an index
DROP INDEX - deletes an index
The SQL SELECT Statement :
The SELECT statement is used to select data from a database.SQL SELECT Syntax
SELECT column_name,column_name
FROM table_name;
and
SELECT * FROM table_name;
Example:
SELECT * FROM Student;
The SQL SELECT DISTINCT Statement
In a table, a column may contain many duplicate values; and sometimes you
only want to list the different (distinct) values.
SELECT DISTINCT column_name,column_name
FROM table_name;
Example:
select distinct Student name from Student ;
The SQL WHERE Clause
The WHERE clause is used to extract only those records that specifies the needs .
SQL WHERE Syntax
SELECT column_name,column_name
FROM table_name
WHERE column_name operator value;
Example
SELECT * FROM Student
WHERE name='Ash';
Operators in The WHERE Clause
The following operators can be used in the WHERE clause:
Operator
Description
=
Equal
<>
Not equal.
>
Greater than
<
Less than
>=
Greater than or equal
<=
Less than or equal
BETWEEN
Between an inclusive range
LIKE
Search for a pattern
IN
To specify multiple possible values for a column