Data Base (DB)
Lab2
ENG: MARWA ABDULLMANNA
Introduction to SQL
SQL (Structured Query Language) is a standardized language used to manage and manipulate
relational databases. It allows users to create, retrieve, update, and delete data efficiently.
Why Use SQL?
•Data Management: SQL helps store and organize large amounts of data.
•Easy to Learn: Simple syntax makes it beginner-friendly.
•Widely Used: SQL is used in almost every industry that deals with databases.
What is SQL?
•SQL stands for Structured Query Language
•SQL lets you access and manipulate databases
•SQL became a standard of the American National Standards Institute (ANSI)
in 1986, and of the International Organization for Standardization (ISO) in
1987
What Can SQL do?
• SQL can execute queries against a database
• 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
Using SQL in Your Web Site
To build a web site that shows data from a database, you will need:
•An RDBMS database program (i.e. MS Access, SQL Server, MySQL)
•To use a server-side scripting language, like PHP or ASP
•To use SQL to get the data you want
•To use HTML / CSS to style the page
RDBMS
stands for Relational Database Management System
RDBMS stands for Relational Database Management System.
RDBMS is the basis for SQL, and for all modern database systems such as MS
SQL Server, IBM DB2, Oracle, MySQL, and Microsoft Access.
The data in RDBMS is stored in database objects called tables. A table is a
collection of related data entries and it consists of columns and rows
SQL Statements
•SELECT - extracts data from a database
•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
SQL Statements
•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 (search key)
•DROP INDEX - deletes an index
SQL SELECT Statement
The SELECT statement is used to select data from a database.
SELECT * or Columns [alias]
FROM Table
WHERE condition or conditions
ORDER BY Column or Alias [ASC or DESC] ;
SQL SELECT Statement
Select * from dept Select deptno , dname from
dept
Aliases
SELECT ename AS name , sal salary , job "employee job " FROM
emp ;
Arithmetic Operators
SELECT ename , sal , sal*12 "annual salary" from emp
Operator Precedence
SELECT ename , sal , 12*sal+100 FROM SELECT ename , sal , 12*sal+100 FROM
emp emp
Concatenation ( + )
SELECT ENAME, JOB, ENAME + ' ' + JOB AS Employees FROM
EMP
DISTINC
SELECT deptno FROM emp SELECT DISTINCT deptno FROM emp
NULL
SELECT ename, job , sal , comm FROM emp
NULL
SELECT ename, job , sal , 12*sal+comm FROM emp
Any Question ?