Lesson Plan Instructional Objective Learning Objective

Slides:



Advertisements
Similar presentations
Copyright © by Royal Institute of Information Technology Introduction To Structured Query Language (SQL) 1.
Advertisements

Fundamentals, Design, and Implementation, 9/e Chapter 6 Introduction to Structured Query Language (SQL)
1ISM - © 2010 Houman Younessi Lecture 3 Convener: Houman Younessi Information Systems Spring 2011.
DATABASES AND SQL. Introduction Relation: Relation means table(data is arranged in rows and columns) Domain : A domain is a pool of values appearing in.
SQL Basics. SQL SQL (Structured Query Language) is a special-purpose programming language designed from managing data in relational database management.
CPS120: Introduction to Computer Science Information Systems: Database Management Nell Dale John Lewis.
LOGO 1 Lab_02: Basic SQL. 2 Outline  Database Tables  SQL Statements  Semicolon after SQL Statements?  SQL DML and DDL  SQL SELECT Statement  SQL.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
Structured Query Language. SQL is an ANSI (American National Standards Institute) standard computer language for accessing and manipulating database systems.
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
SQL SQL Server : Overview SQL : Overview Types of SQL Database : Creation Tables : Creation & Manipulation Data : Creation & Manipulation Data : Retrieving.
ZEIT2301 Design of Information Systems SQL: Computing Statistics School of Engineering and Information Technology Dr Kathryn Merrick.
SQL Basics. 5/27/2016Chapter 32 of 19 Naming SQL commands are NOT case sensitive SQL commands are NOT case sensitive But user identifier names ARE case.
BY SATHISH SQL Basic. Introduction The language Structured English Query Language (SEQUEL) was developed by IBM Corporation, Inc., to use Codd's model.
SQL: DDL. SQL Statements DDL - data definition language –Defining and modifying data structures (metadata): database, tables, views, etc. DML - data manipulation.
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
LOGO 1 Lab_04: Basic SQL. 2 Outline  The ORDER BY Keyword  SQL ORDER BY Syntax  SQL NULL Values.
SQL. คำสั่ง SQL SQL stands for Structured Query Language is a standard language for accessing and manipulating databases.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
# 1# 1 Creating Tables, Setting Constraints, and Datatypes What is a constraint and why do we use it? What is a datatype? What does CHAR mean? CS 105.
SQL LANGUAGE and Relational Data Model TUTORIAL Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
Fox MIS Spring 2011 Database Week 6 ERD and SQL Exercise.
CHAPTER 9 SQL อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1.
>> Introduction to MySQL. Introduction Structured Query Language (SQL) – Standard Database Language – Manage Data in a DBMS (Database Management System)
Chapter 11 Database and SQL. Flat Files and Databases Flat files Databases Advantages Efficient use of resources Access control Disadvantages Security.
Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total.
Introduction to Database SEM I, AY Department of Information Technology Salalah College of Technology Chapter No.3 SQL.
به نام خدا SQL QUIZ جوانمرد Website: ejavanmard.blogfa.com.
SQL: Structured Query Language It enables to create and operate on relational databases, which are sets of related information stored in tables. It is.
MySQL Tutorial. Databases A database is a container that groups together a series of tables within a single structure Each database can contain 1 or more.
Create Stored Procedures and Functions Database Management Fundamentals LESSON 2.4.
Lec-7. The IN Operator The IN operator allows you to specify multiple values in a WHERE clause. SQL IN Syntax SELECT column_name(s) FROM table_name WHERE.
COM621: Advanced Interactive Web Development Lecture 11 MySQL – Data Manipulation Language.
 MySQL is a database system used on the web  MySQL is a database system that runs on a server  MySQL is ideal for both small and large applications.
Standard language for querying and manipulating data Structured Query Language Many standards out there: ANSI SQL, SQL92 (a.k.a. SQL2), SQL99 (a.k.a. SQL3),
Fundamental of Database Systems
SQL SQL Ayshah I. Almugahwi Maryam J. Alkhalifa
Getting started with Accurately Storing Data
Fundamentals of DBMS Notes-1.
How to: SQL By: Sam Loch.
Web Systems & Technologies
From: SQL From:
SQL Query Getting to the data ……..
MySQL DML Commands By Prof. B.A.Khivsara
PL/SQL LANGUAGE MULITPLE CHOICE QUESTION SET-1
Data Definition and Data Types
Database Management  .
SQL FUNDAMENTALS CDSE Days 2018.
SQL Tutorial.
Lecturer: Mukhtar Mohamed Ali “Hakaale”
Structured Query Language
Structured Query Language
Introduction To Structured Query Language (SQL)
Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall
Database systems Lecture 3 – SQL + CRUD
Access: SQL Participation Project
SQL DATA CONSTRAINTS.
SQL.
Structured Query Language – The Fundamentals
Introduction To Structured Query Language (SQL)
Structured Query Language
PHP and MySQL.
More SQL Statements.
កម្មវិធីបង្រៀន SQL Programming ជាភាសាខ្មែរ Online SQL Training Course
កម្មវិធីបង្រៀន SQL Programming ជាភាសាខ្មែរ Online SQL Training Course
SQL NOT NULL Constraint
Introduction to SQL Server and the Structure Query Language
SQL AUTO INCREMENT Field
Presentation transcript:

Lesson Plan Instructional Objective Learning Objective Lession/Topic : SQL functions & Constraints. Class : XII Period : 6th Time : 35 min. Instructional Objective To enable students to acquire the knowledge of MYSQL functions and MYSQL Constraints. Learning Objective To enable students to understand the MYSQL functions and MYSQL Constraints. To enable students to apply the knowledge of MYSQL functions and MYSQL Constraints on tables. Teaching Aid used : LCD projector, White Board, Marker. Life skill : Creativity, Critical Thinking.

SQL Functions and constraints

Instructional Objective * To enable students to acquire the knowledge of MYSQL functions and MYSQL Constraints.

Learning Objective To Enable the student understand of how to apply functions on columns. To Enable the student understand of how to add constraints to table.

Prerequisite Knowledge of Fundamental of DBMS Data types Creating tables in MYSQL.

The AVG() Function The AVG() Function The AVG() function returns the average value of a numeric column. SQL AVG() Syntax SELECT AVG(column_name) FROM table_name;

SELECT AVG(OrderPrice) AS OrderAverage FROM Orders; The result-set will look like this: OrderAverage 950

Count() function SELECT COUNT(*) FROM table_name; The COUNT(column_name) function returns the number of values (NULL values will not be counted) of the specified column:

The MAX() Function The MAX() function returns the largest value of the selected column. SQL MAX() Syntax SELECT MAX(column_name) FROM table_name; SELECT MAX(OrderPrice) AS LargestOrderPrice FROM Orders;

The MIN() Function The MIN() function returns the smallest value of the selected column. SQL MIN() Syntax SELECT MIN(column_name) FROM table_name; SELECT MIN(OrderPrice) AS SmallestOrderPrice FROM Orders;

The SUM() Function The SUM() function returns the total sum of a numeric column. SQL SUM() Syntax SELECT SUM(column_name) FROM table_name; SELECT SUM(OrderPrice) AS OrderTotal FROM Orders;

The UCASE() Function The UCASE() function converts the value of a field to uppercase. SQL UCASE() Syntax SELECT UCASE(column_name) FROM table_name; SELECT UCASE(LastName) as LastName,FirstName FROM Persons;

The LCASE() Function The LCASE() function converts the value of a field to lowercase. SQL LCASE() Syntax SELECT LCASE(column_name) FROM table_name; SELECT LCASE(LastName) as LastName,FirstName FROM Persons;

The MID() Function The MID() function is used to extract characters from a text field. SQL MID() Syntax SELECT MID(column_name,start[,length]) FROM table_name; SELECT MID(City,1,4) as SmallCity FROM Persons;

The LEN() Function The LEN() function returns the length of the value in a text field. SQL LEN() Syntax SELECT LEN(column_name) FROM table_name; SQL LEN() Example SELECT LEN(Address) as LengthOfAddress FROM Persons;

SQL Constraints Constraints are used to limit the type of data that can go into a table. Constraints can be specified when a table is created (with the CREATE TABLE statement) or after the table is created (with the ALTER TABLE statement). We will focus on the following constraints: NOT NULL UNIQUE PRIMARY KEY FOREIGN KEY CHECK DEFAULT

SQL NOT NULL Constraint The NOT NULL constraint enforces a column to NOT accept NULL values. The NOT NULL constraint enforces a field to always contain a value. This means that you cannot insert a new record, or update a record without adding a value to this field. The following SQL enforces the "P_Id" column and the "LastName" column to not accept NULL values: CREATE TABLE Persons ( P_Id int NOT NULL, LastName varchar(255) NOT NULL, FirstName varchar(255), Address varchar(255), City varchar(255) );  

SQL UNIQUE Constraint The following SQL creates a UNIQUE constraint on the "P_Id" column when the "Persons" table is created: CREATE TABLE Persons ( P_Id int NOT NULL, LastName varchar(255) NOT NULL, FirstName varchar(255), Address varchar(255), City varchar(255), UNIQUE (P_Id) );

SQL PRIMARY KEY Constraint The PRIMARY KEY constraint uniquely identifies each record in a database table. Primary keys must contain unique values. A primary key column cannot contain NULL values. Each table should have a primary key, and each table can have only ONE primary key.

SQL PRIMARY KEY Constraint The following SQL creates a PRIMARY KEY on the "P_Id" column when the "Persons" table is created: CREATE TABLE Persons ( P_Id int NOT NULL, LastName varchar(255) NOT NULL, FirstName varchar(255), Address varchar(255), City varchar(255), PRIMARY KEY (P_Id) );

SQL FOREIGN KEY Constraint A FOREIGN KEY in one table points to a PRIMARY KEY in another table. Note that the "P_Id" column in the "Orders" table points to the "P_Id" column in the "Persons" table. The "P_Id" column in the "Persons" table is the PRIMARY KEY in the "Persons" table. The "P_Id" column in the "Orders" table is a FOREIGN KEY in the "Orders" table. The FOREIGN KEY constraint is used to prevent actions that would destroy links between tables. The FOREIGN KEY constraint also prevents that invalid data form being inserted into the foreign key column, because it has to be one of the values contained in the table it points to.

SQL FOREIGN KEY Constraint The following SQL creates a FOREIGN KEY on the "P_Id" column when the "Orders" table is created: CREATE TABLE Orders (O_Id int NOT NULL, OrderNo int NOT NULL, P_Id int, PRIMARY KEY (O_Id), FOREIGN KEY (P_Id) REFERENCES Persons(P_Id) );

SQL CHECK Constraint The CHECK constraint is used to limit the value range that can be placed in a column. If you define a CHECK constraint on a single column it allows only certain values for this column. If you define a CHECK constraint on a table it can limit the values in certain columns based on values in other columns in the row.

SQL CHECK Constraint The following SQL creates a CHECK constraint on the "P_Id" column when the "Persons" table is created. The CHECK constraint specifies that the column "P_Id" must only include integers greater than 0. CREATE TABLE Persons (P_Id int NOT NULL, LastName varchar(255) NOT NULL, FirstName varchar(255), Address varchar(255), City varchar(255), CHECK (P_Id>0) );

SQL DEFAULT Constraint The DEFAULT constraint is used to insert a default value into a column. The default value will be added to all new records, if no other value is specified.

SQL DEFAULT Constraint The following SQL creates a DEFAULT constraint on the "City" column when the "Persons" table is created: CREATE TABLE Persons (P_Id int NOT NULL, LastName varchar(255) NOT NULL, FirstName varchar(255), Address varchar(255), City varchar(255) DEFAULT 'Sandnes' );

SQL Quiz Quiz Time

Which SQL statement is used to update data in a database? MODIFY SAVE UPDATE SAVE AS

Which SQL statement is used to insert new data in a database? ADD RECORD ADD NEW INSERT INTO

With SQL, how can you return the number of records in the "Persons" table? SELECT COLUMNS(*) FROM Persons SELECT COLUMNS() FROM Persons SELECT COUNT() FROM Persons SELECT COUNT(*) FROM Persons

With SQL, how do you select all the columns from a table named "Persons"? SELECT Persons SELECT *.Persons SELECT * FROM Persons SELECT [all] FROM Persons

With SQL, how do you select all the records from a table named "Persons" where the value of the column "FirstName" starts with an "a"? SELECT * FROM Persons WHERE FirstName='%a%' SELECT * FROM Persons WHERE FirstName LIKE '%a' SELECT * FROM Persons WHERE FirstName LIKE 'a%' SELECT * FROM Persons WHERE FirstName='a'

The OR operator displays a record if ANY conditions listed are true The OR operator displays a record if ANY conditions listed are true. The AND operator displays a record if ALL of the conditions listed are true   True False

Which SQL statement is used to return only different values?   SELECT UNIQUE SELECT DISTINCT SELECT DIFFERENT

With SQL, how can you return all the records from a table named "Persons" sorted descending by "FirstName"? SELECT * FROM Persons ORDER FirstName DESC SELECT * FROM Persons SORT 'FirstName' DESC SELECT * FROM Persons ORDER BY FirstName DESC SELECT * FROM Persons SORT BY 'FirstName' DESC

How can you change "Hansen" into "Nilsen" in the "LastName" column in the Persons table? UPDATE Persons SET LastName='Hansen' INTO LastName='Nilsen' UPDATE Persons SET LastName='Nilsen' WHERE LastName='Hansen' MODIFY Persons SET LastName='Hansen' INTO LastName='Nilsen MODIFY Persons SET LastName='Nilsen' WHERE LastName='Hansen'

With SQL, how can you return the number of records in the "Persons" table? SELECT COLUMNS(*) FROM Persons SELECT COLUMNS() FROM Persons SELECT COUNT() FROM Persons SELECT COUNT(*) FROM Persons