SlideShare a Scribd company logo
1 of 18
Download to read offline
Introduction to SQL 
(Standard Query Language)
Domain Types in SQL 
 char(n). Fixed length character string, with user-specified length n. 
 varchar(n). Variable length character strings, with user-specified 
maximum length n. 
 int. Integer (a finite subset of the integers that is machine-dependent). 
 smallint. Small integer (a machine-dependent subset of the integer 
domain type). 
 numeric(p,d). Fixed point number, with user-specified precision of 
p digits, with n digits to the right of decimal point. 
 real, double precision. Floating point and double-precision floating 
point numbers, with machine-dependent precision. 
 float(n). Floating point number, with user-specified precision of at 
least n digits. 
 More are covered in Chapter 4.
Create Database Construct 
 CREATE DATABASE dbname; 
 Example: 
CREATE DATABASE my_db; 
Create Table Construct 
 CREATE TABLE table_name 
( 
column_name1 data_type(size), 
column_name2 data_type(size), 
.... 
); 
 Example: 
create table instructor ( 
ID char(5), 
name varchar(20) not null, 
dept_name varchar(20), 
salary numeric(8,2))
Integrity Constraints in Create Table 
 not null 
 primary key (A1, ..., An ) 
 foreign key (Am, ..., An ) references r 
Example: Declare ID as the primary key for instructor 
. 
CREATE TABLE Persons 
( 
ID int NOT NULL, 
LastName varchar(255) NOT NULL, 
FirstName varchar(255), 
PRIMARY KEY (ID) 
); 
primary key declaration on an attribute automatically ensures not null
Integrity Constraints in Create Table 
 CREATE TABLE Orders 
( 
O_Id int NOT NULL, 
OrderDetails varchar(255) NOT NULL, 
P_Id int, 
PRIMARY KEY (O_Id), 
FOREIGN KEY (P_Id) REFERENCES Persons(ID) 
);
Insert into table 
 INSERT INTO table_name 
VALUES (value1,value2,value3,...); 
 Example: 
 insert into instructor values (‘10211’, ’Smith’, ’Biology’, 
66000); 
 insert into instructor values (‘10211’, null, ’Biology’, 66000);
Basic Query Structure 
 A typical SQL query has the form: 
select A1, A2, ..., An 
from r1, r2, ..., rm 
where P 
 Ai represents an attribute (desired column names) 
 Ri represents a relation (table names) 
 P is a predicate (Condition)
The select Clause 
 Example: find the names of all instructors: 
select name 
from instructor 
 NOTE: SQL names are case insensitive (i.e., you may use upper- or 
lower-case letters.) 
 E.g. Name ≡ NAME ≡ name 
 Some people use upper case wherever we use bold font.
The select Clause (Cont.) 
distinct 
 Find the names of all departments with instructor, and remove 
duplicates 
select distinct dept_name 
from instructor 
all 
 The keyword all specifies that duplicates not be removed. 
select all dept_name 
from instructor
The select Clause (Cont.) 
 An asterisk in the select clause denotes “all attributes” 
select * 
from instructor 
 The select clause can contain arithmetic expressions involving 
the operation, +, –, , and /, and operating on constants or 
attributes of tuples. 
 The query: 
select ID, name, salary/12 
from instructor 
would return a relation that is the same as the instructor relation, 
except that the value of the attribute salary is divided by 12.
The where Clause 
 To find all instructors in Comp. Sci. dept with salary > 80000 
select name 
from instructor 
where dept_name = ‘Comp. Sci.' and salary > 80000 
 Comparison results can be combined using the logical 
connectives and, or, and not. 
 Comparisons can be applied to results of arithmetic expressions 
(<=, <, >, >=, !=).
Where Clause Predicates 
between 
 Example: Find the names of all instructors with salary between 
$90,000 and $100,000 (that is,  $90,000 and  $100,000) 
 select name 
from instructor 
where salary between 90000 and 100000 
 select name, course_id 
from instructor, teaches 
where (instructor.ID, dept_name) = (teaches.ID, ’Biology’);
The from Clause 
 The from clause lists the relations involved in the query 
select  
from instructor, teaches 
 generates every possible instructor – teaches pair, with all 
attributes from both relations
Drop and Alter Table Constructs 
 drop table customers 
 Deletes the table and its contents 
>>DROP TABLE table_name 
>>DROP DATABASE database_name 
 delete from customers 
 Deletes all contents of table, but retains table 
 DELETE FROM Customers 
WHERE CustomerName='Alfreds Futterkiste' AND 
ContactName='Maria Anders';
Drop and Alter Table Constructs 
 alter table 
 alter table- add 
 ALTER TABLE table_name 
ADD column_name datatype 
 ALTER TABLE Customers 
ADD Customer_Joindate Date 
 alter table- drop 
 ALTER TABLE table_name 
DROP COLUMN column_name 
 ALTER TABLE Customers 
DROP Customer_Joindate Date
The Rename (As) Operation 
 The SQL allows renaming relations and attributes using the as clause: 
old-name as new-name 
 E.g. 
 select ID, name, salary/12 as monthly_salary 
from instructor 
 Find the names of all instructors who have a higher salary than 
some instructor in ‘Comp. Sci’. 
 select distinct T. name 
from instructor as T, instructor as S 
where T.salary > S.salary and S.dept_name = ‘Comp. Sci.’
Like- String Operations 
 percent (%). The % character matches any substring. 
 underscore (_). The _ character matches any character. 
 Find the names of all instructors whose name includes the substring 
“dar”. 
select name 
from instructor 
where name like '%dar%' 
 Match the string “100 %” 
select name 
from instructor 
where attendance like ‘100 %' escape ''
Order by - Ordering the Display of 
Tuples 
 List in alphabetic order the names of all instructors 
select distinct name 
from instructor 
order by name 
 We may specify desc for descending order or asc for 
ascending order, for each attribute; ascending order is the 
default. 
 Example: order by name desc 
 Can sort on multiple attributes 
 Example: order by dept_name, name

More Related Content

What's hot (20)

Presentation slides of Sequence Query Language (SQL)
Presentation slides of Sequence Query Language (SQL)Presentation slides of Sequence Query Language (SQL)
Presentation slides of Sequence Query Language (SQL)
 
SQL Views
SQL ViewsSQL Views
SQL Views
 
Sql operators & functions 3
Sql operators & functions 3Sql operators & functions 3
Sql operators & functions 3
 
SQL Tutorial - Basic Commands
SQL Tutorial - Basic CommandsSQL Tutorial - Basic Commands
SQL Tutorial - Basic Commands
 
SQL
SQLSQL
SQL
 
Introduction to SQL
Introduction to SQLIntroduction to SQL
Introduction to SQL
 
set operators.pptx
set operators.pptxset operators.pptx
set operators.pptx
 
Including Constraints -Oracle Data base
Including Constraints -Oracle Data base Including Constraints -Oracle Data base
Including Constraints -Oracle Data base
 
Sql ppt
Sql pptSql ppt
Sql ppt
 
SQL Queries
SQL QueriesSQL Queries
SQL Queries
 
MySQL and its basic commands
MySQL and its basic commandsMySQL and its basic commands
MySQL and its basic commands
 
Sql subquery
Sql  subquerySql  subquery
Sql subquery
 
MYSQL.ppt
MYSQL.pptMYSQL.ppt
MYSQL.ppt
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
A must Sql notes for beginners
A must Sql notes for beginnersA must Sql notes for beginners
A must Sql notes for beginners
 
SQL Functions and Operators
SQL Functions and OperatorsSQL Functions and Operators
SQL Functions and Operators
 
SQL Server Learning Drive
SQL Server Learning Drive SQL Server Learning Drive
SQL Server Learning Drive
 
Basic SQL and History
 Basic SQL and History Basic SQL and History
Basic SQL and History
 
SQL BASIC QUERIES SOLUTION ~hmftj
SQL BASIC QUERIES SOLUTION ~hmftjSQL BASIC QUERIES SOLUTION ~hmftj
SQL BASIC QUERIES SOLUTION ~hmftj
 
Sql queries presentation
Sql queries presentationSql queries presentation
Sql queries presentation
 

Similar to SQL : introduction

Similar to SQL : introduction (20)

SQL.ppt
SQL.pptSQL.ppt
SQL.ppt
 
Db1 lecture4
Db1 lecture4Db1 lecture4
Db1 lecture4
 
Unit04 dbms
Unit04 dbmsUnit04 dbms
Unit04 dbms
 
Chapter08
Chapter08Chapter08
Chapter08
 
Module03
Module03Module03
Module03
 
Exploring collections with example
Exploring collections with exampleExploring collections with example
Exploring collections with example
 
DEE 431 Introduction to MySql Slide 6
DEE 431 Introduction to MySql Slide 6DEE 431 Introduction to MySql Slide 6
DEE 431 Introduction to MySql Slide 6
 
PPT
PPTPPT
PPT
 
Chinabankppt
ChinabankpptChinabankppt
Chinabankppt
 
ch3.ppt
ch3.pptch3.ppt
ch3.ppt
 
Introduction to SQL
Introduction to SQLIntroduction to SQL
Introduction to SQL
 
ch3.ppt
ch3.pptch3.ppt
ch3.ppt
 
ch3.ppt
ch3.pptch3.ppt
ch3.ppt
 
ch3.ppt
ch3.pptch3.ppt
ch3.ppt
 
Ch 3.pdf
Ch 3.pdfCh 3.pdf
Ch 3.pdf
 
ch3.ppt
ch3.pptch3.ppt
ch3.ppt
 
75864 sql
75864 sql75864 sql
75864 sql
 
mysql.ppt
mysql.pptmysql.ppt
mysql.ppt
 
Database queries
Database queriesDatabase queries
Database queries
 
SQL select statement and functions
SQL select statement and functionsSQL select statement and functions
SQL select statement and functions
 

More from Shakila Mahjabin (15)

Computer processing
Computer processingComputer processing
Computer processing
 
Arrays in CPP
Arrays in CPPArrays in CPP
Arrays in CPP
 
CSC 433 Sample normalization SQL Question
CSC 433 Sample normalization SQL QuestionCSC 433 Sample normalization SQL Question
CSC 433 Sample normalization SQL Question
 
Normalization
NormalizationNormalization
Normalization
 
Solution of Erds
Solution of ErdsSolution of Erds
Solution of Erds
 
Entity Relationship Diagram
Entity Relationship DiagramEntity Relationship Diagram
Entity Relationship Diagram
 
Ch1- Introduction to dbms
Ch1- Introduction to dbmsCh1- Introduction to dbms
Ch1- Introduction to dbms
 
Stack and queue
Stack and queueStack and queue
Stack and queue
 
Algo analysis
Algo analysisAlgo analysis
Algo analysis
 
Merge sort and quick sort
Merge sort and quick sortMerge sort and quick sort
Merge sort and quick sort
 
Codes on structures
Codes on structuresCodes on structures
Codes on structures
 
Arrays
ArraysArrays
Arrays
 
array, function, pointer, pattern matching
array, function, pointer, pattern matchingarray, function, pointer, pattern matching
array, function, pointer, pattern matching
 
String operation
String operationString operation
String operation
 
Data Structure Basics
Data Structure BasicsData Structure Basics
Data Structure Basics
 

Recently uploaded

Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operationalssuser3e220a
 
Mythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWMythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWQuiz Club NITW
 
Using Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea DevelopmentUsing Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea Developmentchesterberbo7
 
CHEST Proprioceptive neuromuscular facilitation.pptx
CHEST Proprioceptive neuromuscular facilitation.pptxCHEST Proprioceptive neuromuscular facilitation.pptx
CHEST Proprioceptive neuromuscular facilitation.pptxAneriPatwari
 
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptx
Unraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptxUnraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptx
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptxDhatriParmar
 
CLASSIFICATION OF ANTI - CANCER DRUGS.pptx
CLASSIFICATION OF ANTI - CANCER DRUGS.pptxCLASSIFICATION OF ANTI - CANCER DRUGS.pptx
CLASSIFICATION OF ANTI - CANCER DRUGS.pptxAnupam32727
 
4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptxmary850239
 
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxGrade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxkarenfajardo43
 
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvRicaMaeCastro1
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 
4.9.24 School Desegregation in Boston.pptx
4.9.24 School Desegregation in Boston.pptx4.9.24 School Desegregation in Boston.pptx
4.9.24 School Desegregation in Boston.pptxmary850239
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationdeepaannamalai16
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSMae Pangan
 
Sulphonamides, mechanisms and their uses
Sulphonamides, mechanisms and their usesSulphonamides, mechanisms and their uses
Sulphonamides, mechanisms and their usesVijayaLaxmi84
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQ-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQuiz Club NITW
 
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...DhatriParmar
 

Recently uploaded (20)

Mattingly "AI & Prompt Design: Large Language Models"
Mattingly "AI & Prompt Design: Large Language Models"Mattingly "AI & Prompt Design: Large Language Models"
Mattingly "AI & Prompt Design: Large Language Models"
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operational
 
Mythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWMythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITW
 
Using Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea DevelopmentUsing Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea Development
 
CHEST Proprioceptive neuromuscular facilitation.pptx
CHEST Proprioceptive neuromuscular facilitation.pptxCHEST Proprioceptive neuromuscular facilitation.pptx
CHEST Proprioceptive neuromuscular facilitation.pptx
 
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptx
Unraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptxUnraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptx
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptx
 
CLASSIFICATION OF ANTI - CANCER DRUGS.pptx
CLASSIFICATION OF ANTI - CANCER DRUGS.pptxCLASSIFICATION OF ANTI - CANCER DRUGS.pptx
CLASSIFICATION OF ANTI - CANCER DRUGS.pptx
 
4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx
 
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxGrade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
 
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 
4.9.24 School Desegregation in Boston.pptx
4.9.24 School Desegregation in Boston.pptx4.9.24 School Desegregation in Boston.pptx
4.9.24 School Desegregation in Boston.pptx
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentation
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHS
 
Sulphonamides, mechanisms and their uses
Sulphonamides, mechanisms and their usesSulphonamides, mechanisms and their uses
Sulphonamides, mechanisms and their uses
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQ-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
 
Faculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Faculty Profile prashantha K EEE dept Sri Sairam college of EngineeringFaculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Faculty Profile prashantha K EEE dept Sri Sairam college of Engineering
 
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
 

SQL : introduction

  • 1. Introduction to SQL (Standard Query Language)
  • 2. Domain Types in SQL  char(n). Fixed length character string, with user-specified length n.  varchar(n). Variable length character strings, with user-specified maximum length n.  int. Integer (a finite subset of the integers that is machine-dependent).  smallint. Small integer (a machine-dependent subset of the integer domain type).  numeric(p,d). Fixed point number, with user-specified precision of p digits, with n digits to the right of decimal point.  real, double precision. Floating point and double-precision floating point numbers, with machine-dependent precision.  float(n). Floating point number, with user-specified precision of at least n digits.  More are covered in Chapter 4.
  • 3. Create Database Construct  CREATE DATABASE dbname;  Example: CREATE DATABASE my_db; Create Table Construct  CREATE TABLE table_name ( column_name1 data_type(size), column_name2 data_type(size), .... );  Example: create table instructor ( ID char(5), name varchar(20) not null, dept_name varchar(20), salary numeric(8,2))
  • 4. Integrity Constraints in Create Table  not null  primary key (A1, ..., An )  foreign key (Am, ..., An ) references r Example: Declare ID as the primary key for instructor . CREATE TABLE Persons ( ID int NOT NULL, LastName varchar(255) NOT NULL, FirstName varchar(255), PRIMARY KEY (ID) ); primary key declaration on an attribute automatically ensures not null
  • 5. Integrity Constraints in Create Table  CREATE TABLE Orders ( O_Id int NOT NULL, OrderDetails varchar(255) NOT NULL, P_Id int, PRIMARY KEY (O_Id), FOREIGN KEY (P_Id) REFERENCES Persons(ID) );
  • 6. Insert into table  INSERT INTO table_name VALUES (value1,value2,value3,...);  Example:  insert into instructor values (‘10211’, ’Smith’, ’Biology’, 66000);  insert into instructor values (‘10211’, null, ’Biology’, 66000);
  • 7. Basic Query Structure  A typical SQL query has the form: select A1, A2, ..., An from r1, r2, ..., rm where P  Ai represents an attribute (desired column names)  Ri represents a relation (table names)  P is a predicate (Condition)
  • 8. The select Clause  Example: find the names of all instructors: select name from instructor  NOTE: SQL names are case insensitive (i.e., you may use upper- or lower-case letters.)  E.g. Name ≡ NAME ≡ name  Some people use upper case wherever we use bold font.
  • 9. The select Clause (Cont.) distinct  Find the names of all departments with instructor, and remove duplicates select distinct dept_name from instructor all  The keyword all specifies that duplicates not be removed. select all dept_name from instructor
  • 10. The select Clause (Cont.)  An asterisk in the select clause denotes “all attributes” select * from instructor  The select clause can contain arithmetic expressions involving the operation, +, –, , and /, and operating on constants or attributes of tuples.  The query: select ID, name, salary/12 from instructor would return a relation that is the same as the instructor relation, except that the value of the attribute salary is divided by 12.
  • 11. The where Clause  To find all instructors in Comp. Sci. dept with salary > 80000 select name from instructor where dept_name = ‘Comp. Sci.' and salary > 80000  Comparison results can be combined using the logical connectives and, or, and not.  Comparisons can be applied to results of arithmetic expressions (<=, <, >, >=, !=).
  • 12. Where Clause Predicates between  Example: Find the names of all instructors with salary between $90,000 and $100,000 (that is,  $90,000 and  $100,000)  select name from instructor where salary between 90000 and 100000  select name, course_id from instructor, teaches where (instructor.ID, dept_name) = (teaches.ID, ’Biology’);
  • 13. The from Clause  The from clause lists the relations involved in the query select  from instructor, teaches  generates every possible instructor – teaches pair, with all attributes from both relations
  • 14. Drop and Alter Table Constructs  drop table customers  Deletes the table and its contents >>DROP TABLE table_name >>DROP DATABASE database_name  delete from customers  Deletes all contents of table, but retains table  DELETE FROM Customers WHERE CustomerName='Alfreds Futterkiste' AND ContactName='Maria Anders';
  • 15. Drop and Alter Table Constructs  alter table  alter table- add  ALTER TABLE table_name ADD column_name datatype  ALTER TABLE Customers ADD Customer_Joindate Date  alter table- drop  ALTER TABLE table_name DROP COLUMN column_name  ALTER TABLE Customers DROP Customer_Joindate Date
  • 16. The Rename (As) Operation  The SQL allows renaming relations and attributes using the as clause: old-name as new-name  E.g.  select ID, name, salary/12 as monthly_salary from instructor  Find the names of all instructors who have a higher salary than some instructor in ‘Comp. Sci’.  select distinct T. name from instructor as T, instructor as S where T.salary > S.salary and S.dept_name = ‘Comp. Sci.’
  • 17. Like- String Operations  percent (%). The % character matches any substring.  underscore (_). The _ character matches any character.  Find the names of all instructors whose name includes the substring “dar”. select name from instructor where name like '%dar%'  Match the string “100 %” select name from instructor where attendance like ‘100 %' escape ''
  • 18. Order by - Ordering the Display of Tuples  List in alphabetic order the names of all instructors select distinct name from instructor order by name  We may specify desc for descending order or asc for ascending order, for each attribute; ascending order is the default.  Example: order by name desc  Can sort on multiple attributes  Example: order by dept_name, name