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.

Slides:



Advertisements
Similar presentations
SQL Rohit Khokher.
Advertisements

Basic SQL Introduction Presented by: Madhuri Bhogadi.
Pertemuan ke 2 Tipe data & ERD Kurniawan Eka Permana.
Copyright © by Royal Institute of Information Technology Introduction To Structured Query Language (SQL) 1.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 SQL: Data Definition, Constraints, and Basic Queries and Updates.
Fundamentals, Design, and Implementation, 9/e COS 346 Day 11.
Introduction to Structured Query Language (SQL)
Fundamentals, Design, and Implementation, 9/e Chapter 6 Introduction to Structured Query Language (SQL)
Murali Mani SQL DDL and Oracle utilities. Murali Mani Datatypes in SQL INT (or) INTEGER FLOAT (or) REAL DECIMAL (n, m) CHAR (n) VARCHAR (n) DATE, TIME.
Chapter 7: SQL, the Structured Query Language Soid Quintero & Ervi Bongso CS157B.
Chapter 3: SQL Data Definition Language Data Definition Language Basic Structure of SQL Basic Structure of SQL Set Operations Set Operations Aggregate.
Introduction to SQL  SQL or sequel  It is a standardised language with thousands of pages in the standard  It can be in database system through GUI,
Copyright © Curt Hill SQL The Data Definition Language.
Structured Query Language (SQL) A2 Teacher Up skilling LECTURE 2.
Rationale Aspiring Database Developers should be able to efficiently query and maintain databases. This module will help students learn the Structured.
Chapter 9 SQL and RDBMS Part C. SQL Copyright 2005 Radian Publishing Co.
CSE314 Database Systems Lecture 4 Basic SQL Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson Ed Slide Set.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
Chapter 8 Part 1 SQL-99 Schema Definition, Constraints, Queries, and Views.
Chapter 7 SQL HUANG XUEHUA. SQL SQL server2005 introduction Install components  management studio.
CSC 2720 Building Web Applications Database and SQL.
Structure Query Language SQL. Database Terminology Employee ID 3 3 Last name Small First name Tony 5 5 Smith James
SQL SQL Server : Overview SQL : Overview Types of SQL Database : Creation Tables : Creation & Manipulation Data : Creation & Manipulation Data : Retrieving.
SQL FUNDAMENTALS SQL ( Structured Query Language )
1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV.
Nitin Singh/AAO RTI ALLAHABAD 1 SQL Nitin Singh/AAO RTI ALLAHABAD 2 OBJECTIVES §What is SQL? §Types of SQL commands and their function §Query §Index.
Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 6/1 Copyright © 2004 Please……. No Food Or Drink in the class.
Topic 1: Introduction to SQL. SQL stands for Structured Query Language. SQL is a standard computer language for accessing and manipulating databases SQL.
Chapter 8: SQL. Data Definition Modification of the Database Basic Query Structure Aggregate Functions.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
SQL Fundamentals  SQL: Structured Query Language is a simple and powerful language used to create, access, and manipulate data and structure in the database.
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
Database Management COP4540, SCS, FIU Structured Query Language (Chapter 8)
Advanced Database CS-426 Week 1 - Introduction. Database Management System DBMS contains information about a particular enterprise Collection of interrelated.
Fox MIS Spring 2011 Database Week 5 SQL basics SELECT, INSERT, UPDATE, DELETE.
DBSQL 5-1 Copyright © Genetic Computer School 2009 Chapter 5 Structured Query Language.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
Visual Programing SQL Overview Section 1.
SQL – Structured Query Language
1 SQL SQL (Structured Query Language) : is a database language that is used to create, modify and update database design and data. Good Example of DBMS’s.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
Sql DDL queries CS 260 Database Systems.
CMPT 258 Database Systems The Relationship Model (Chapter 3)
Week 8-9 SQL-1. SQL Components: DDL, DCL, & DML SQL is a very large and powerful language, but every type of SQL statement falls within one of three main.
SQL Overview Structured Query Language
1 CS 430 Database Theory Winter 2005 Lecture 11: SQL DDL.
1 MySQL and SQL. 2 Topics  Introducing Relational Databases  Terminology  Managing Databases MySQL and SQL.
Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total.
Oracle & SQL. Oracle Data Types Character Data Types: Char(2) Varchar (20) Clob: large character string as long as 4GB Bolb and bfile: large amount of.
Introduction to Database SEM I, AY Department of Information Technology Salalah College of Technology Chapter No.3 SQL.
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
SQL: Structured Query Language It enables to create and operate on relational databases, which are sets of related information stored in tables. It is.
LECTURE FOUR Introduction to SQL DDL with tables DML with tables.
Big Data Yuan Xue CS 292 Special topics on.
SQL and Relational Algebra Edel Sherratt Nigel Hardy Horst Holstein.
SQL Query Getting to the data ……..
Managing Tables, Data Integrity, Constraints by Adrienne Watt
Introduction to Structured Query Language(SQL)
PL/SQL LANGUAGE MULITPLE CHOICE QUESTION SET-1
DATABASE MANAGEMENT SYSTEM
Database systems Lecture 3 – SQL + CRUD
SQL-1 Week 8-9.
Session - 6 Sequence - 1 SQL: The Structured Query Language:
Contents Preface I Introduction Lesson Objectives I-2
Instructor: SAMIA ARSHAD
Structured Query Language Path from Unorganized to Organized….
SQL (Structured Query Language)
Introduction to SQL Server and the Structure Query Language
Presentation transcript:

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 given column. Eg:

Tuple : The rows of a relation Attribute : The columns of a relation. Attributes Tuple

Degree : Number of attributes(columns) Cardinality: Number of tuples(rows) Degree 2 Cardinality 4

Key Primary Key: Set of one of one more attribute that can uniquely identify tuples within a relation Candidate key: is one or more column in table that uniquely identify each row in a table (can act as primary key). Alternate Key: candidate key is not a primary key

Data types SQL data types are classified into three Numeric String Date

1. Numeric data type: - Length of numeric data type Range decimal places ( 0 to 30) - decimal must be 2 less than length - 2 categories of integer data types are integer(whole numbers) data type TINYINT, SMALLINT, MEDIUMINT, INT, INTEGER, BIGINT Floating point data types are FLOAT,DOUBLE, DOUBLEPRECISION, REAL, DECIMAL, DEC, NUMERIC, FIXED

2. String data types - used to store various types of data - four categories of string data types are CHARACTER, BINARY, TEXT and LIST commonly used data type is character character is classified in two Char uses n byte storage (blank spaced filled with space) varchar uses less storage space

3. Date & Time -yyyy –mm-dd format categories of date & time data types DATE, TIME, DATETIME,YEAR, TIMESTAMP

SQL Statements Sql is made up of set of statements that define the structure of database, store and manage data within that structure and control access to data. Sql statements are mainly divided in to three categories DDL(Data Definition Language) DML(Data Manipulation Language) DCL(Data Control Language)

DDL -( Data Definition Language ) DDL statements create, alter and delete data structure within table. DDL statements defines the type.Eg: create, alter, Drop DML – (Data Manipulation Language ) DML is concerned with data stored in a table. Eg: Insert, update, delete and select. DCL – (Data Control Language) DCL statements controlling the access to database. Eg: grant and revoke.

CREATE TABLE command Create table ( [ ][NOT NULL|NULL][DEFAULT ] [PRIMARY KEY( ],[CHECK EXPRESSION][UNIQUE],..)

Example create table student ( rollno int primary key,column level definition name char (10) );

Create a table student using following information create table student ( Rollno int(4) Primary key, Name varchar(10) Total int(2)); you can’t define a primary key on multiple columns at the column level Column nameData typeSizeconstrain RollnoInt4Primary key NameVarchar10 TotalInt2

INSERT Command To insert row in table Syntax 1 : INSERT INTO (,..) VALUES (,..); Eg: Insert into student (rollno, name,total) values (12101,’arun’,400); if column name are included value clause must include a value for each column

Format 2 INSERT INTO VALUES (,..), Insert into student values (12101,’arun’,400), values(12102,’anil’, 500);

INSERT INTO VALUES (,..), (,..), Eg: Insert into student values (12101,’arun’,400), (12102,’anil’, 500), (12103,’amit’,550), (12104,neem,450);

*Points to remember inserting number : inserting char : inserting date :<’yyyy-mm-dd’) inserting null : NULL  if column name are not included you must provide value for every column in table

UPDATE Command To modify the existing row content UPDATE SET [where ]; where clause determines the which row in a table are updated. Eg : Update student set total =450 where rollno=12101;

DELETE Command To remove row /data from a table DELETE FROM [where expression]; Eg : delete from student where roll = 12102;

SELECT Command To retrieve data from MySql tables we can use SELECT statement SELECT {ALL | DISTINCT } {* | | [AS] } FROM { }{,[ ]}{…….} [WHERE ] [GROUP BY ] [HAVING ] [ORDER BY ]

Select command let you to make queries on the database Form1: To retrive columns Select [, colum name, colum name …] from ; Eg : select rollno, name from student; Form 2: if you want to see the entire table. The (*) can be substituted. Select * from Eg: Select * from student;

Select with - DISTINCT clause or ALL To eliminate duplicates rows from result of a SELECT statement. Form 3 Select DISTINCT column name from Eg: Select distinct name from student; Form 4 Select ALL column name from Eg: Select ALL name from student;

Retrieving specific rows – where clause Select [, colum name, colum name …] from where ; Eg: select * from student where rollno=12101; Relational operators: (Greater than), =(greater than or equal), =(Equal),!= or <>(Not equal). Logical operator : and, or not

Between clause – to set range Select [, colum name, colum name …] from [where column name between value1 and value 2 ; The above statement means Select [, colum name, colum name …] from [where column name>= value1 and column name <= value 2 ; Eg: select * from student where total between 400 and 500. select * from student where total >= 400 and total<= 500.

IN clause – to select values Select [, colum name, colum name …] from [where column name IN( value1,value 2) ; The above statement means Select [, colum name, colum name …] from [where column name= value1 or column name < value 2 ; Eg: select * from student where total IN(400, 500). select * from student where total = 400 or total = 500.

Order by clause – for Sorting - Arrange rows in either ascending / descending order Select [, colum name, colum name …] from [where order by [asc/desc]] Default sorting ascending order(asc) Eg: select * from student where total >= 400 and total<= 500 order by name.

Group by – for grouping similar records Select [, column name, column name …] from [ group by having ] If you are using group by clause and you want to restrict rows use having clause instead of where. Eg: select * from student where group by total having total >= 400 and total<= 500.

Group functions MAX() -> Returns Maximum value from a given column MIN() -> Returns Maximum value from a given column AVG() -> Returns Average value from a given column SUM()-> Returns Sum of values in a given column COUNT() -> count number of rows (Excluding NULL) : COUNT(*) -> returns number of rows( including null)

Group function - Example Select Sum(Total) from student; Select Max(Total) from student; Select Min(Total) from student; Select Avg(Total) from student; Select count() from student; Select Count(*) from student;

THANK YOU