CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.

Slides:



Advertisements
Similar presentations
SQL Rohit Khokher.
Advertisements

MySQL. To start go to Login details: login: labuser password:macimd15 – There.
Database Systems: Design, Implementation, and Management Tenth Edition
Copyright © by Royal Institute of Information Technology Introduction To Structured Query Language (SQL) 1.
Day 3 - Basics of MySQL What is MySQL What is MySQL How to make basic tables How to make basic tables Simple MySQL commands. Simple MySQL commands.
Introduction to Structured Query Language (SQL)
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)
30-Jun-15 SQL A Brief Introduction. SQL SQL is Structured Query Language Some people pronounce SQL as “sequel” Other people insist that only “ess-cue-ell”
Introduction to Structured Query Language (SQL)
Creating Database Tables CS 320. Review: Levels of data models 1. Conceptual: describes WHAT data the system contains 2. Logical: describes HOW the database.
A Guide to MySQL 3. 2 Objectives Start MySQL and learn how to use the MySQL Reference Manual Create a database Change (activate) a database Create tables.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 7 Introduction to Structured Query Language (SQL)
DAT702.  Standard Query Language  Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.
Phonegap Bridge – File System CIS 136 Building Mobile Apps 1.
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.
Structured Query Language (SQL) A2 Teacher Up skilling LECTURE 2.
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
Chapter 5 Introduction to SQL. Structured Query Language = the “programming language” for relational databases SQL is a nonprocedural language = the user.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor Ms. Arwa.
 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 8 Part 1 SQL-99 Schema Definition, Constraints, Queries, and Views.
Chapter 7 SQL HUANG XUEHUA. SQL SQL server2005 introduction Install components  management studio.
Introduction to MySQL Lab no. 10 Advance Database Management System.
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.
Chapter 5: Part 1: DDL STRUCTURED QUERY LANGUAGE (SQL)
1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Chapter 5 MYSQL Database. Introduction to MYSQL MySQL is the world's most popular open-source database. Open source means that the source code, the programming.
Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 6/1 Copyright © 2004 Please……. No Food Or Drink in the class.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
BIS Database Systems School of Management, Business Information Systems, Assumption University A.Thanop Somprasong Chapter # 7 Introduction to Structured.
Topic 1: Introduction to SQL. SQL stands for Structured Query Language. SQL is a standard computer language for accessing and manipulating databases SQL.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
5. Simple SQL using Oracle1 Simple SQL using Oracle 5. Working with Tables: Data management and Retrieval 6. Working with Tables: Functions and Grouping.
SQL Fundamentals  SQL: Structured Query Language is a simple and powerful language used to create, access, and manipulate data and structure in the database.
Advanced Database CS-426 Week 1 - Introduction. Database Management System DBMS contains information about a particular enterprise Collection of interrelated.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
Visual Programing SQL Overview Section 1.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
Fox MIS Spring 2011 Database Week 6 ERD and SQL Exercise.
Sql DDL queries CS 260 Database Systems.
ITEC 3220A Using and Designing Database Systems Instructor: Prof. Z. Yang Course Website: 3220a.htm
CMPT 258 Database Systems The Relationship Model (Chapter 3)
ITS232 Introduction To Database Management Systems Siti Nurbaya Ismail Faculty of Computer Science & Mathematics, Universiti Teknologi MARA (UiTM), Kedah.
>> Introduction to MySQL. Introduction Structured Query Language (SQL) – Standard Database Language – Manage Data in a DBMS (Database Management System)
1 CS 430 Database Theory Winter 2005 Lecture 11: SQL DDL.
Relational Databases and MySQL. Relational Databases Relational databases model data by storing rows and columns in tables. The power of the relational.
Relational Database Management System(RDBMS) Structured Query Language(SQL)
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
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.
SQL Introduction SQL stands for “Structured Query Language” and can be pronounced as “SQL” or “sequel – (Structured English.
3 A Guide to MySQL.
CHAPTER 7 DATABASE ACCESS THROUGH WEB
SQL Query Getting to the data ……..
CS 3630 Database Design and Implementation
Chapter 5 Introduction to SQL.
Managing Tables, Data Integrity, Constraints by Adrienne Watt
PL/SQL LANGUAGE MULITPLE CHOICE QUESTION SET-1
ORACLE SQL Developer & SQLPLUS Statements
Contents Preface I Introduction Lesson Objectives I-2
Database Systems: Design, Implementation, and Management Tenth Edition
MySQL Database System Installation Overview SQL summary
SQL (Structured Query Language)
Presentation transcript:

CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND

Introduction  SQL, Structured Query Language, was developed in 1970s in an IBM Laboratory.  SQL sometimes also referred to as SEQUEL is a 4 th generation non- procedural language.  SQL, being non-procedural, describes WHAT all data is to be retrieved or inserted or modified or deleted, rather than specifying code describing HOW to perform the entire operation

 SQL, enables the following: (i) Creating / modifying a database’s structure (ii) Changing security settings for system (iii) Permitting users for working on databases or tables (iv) Querying database (v) Inserting / Modifying/Deleting the database contents.

 SQL Elements in MySQL The MySQL implementation of SQL has certain elements that play an important role in defining /querying a database. These basic elements are: (i) Literals (ii) Data types (iii) Nulls (iv) Comments  Literals: Literals refers to the fixed data value. It may be Numeric or Character. Numeric literals may be integer or real numbers and Character literals must be closed in single quotes like ‘Hello’.

 data types: To identify the type of data and associated operations for handling it.  Null values: If a column in a row has no value then it is said to NULL. The Null should not be used as a Zero value. Nulls can appear in columns of any data type provided they are not restricted by NOT NULL or PRIMARY KEY integrity constraints.  Comment:  /*…. */ => (Multi line comment)  -- =>(single line comment)  # =>single line comment from the appearance)

 Numeric Data Types: MySQL uses all the standard ANSI SQL numeric data types.  The following list shows the common numeric data types  INTEGER or INT : up to 11 digit number without decimal.  SMALLINT:up to 5 digit number without decimal.  FLOAT (M,D):Real numbers up to M digit with D decimal places. Ex. Float (10,2)  DECIMAL(M,D) or NUMERIC(M,D):Unpacked floating point up to M length and D decimal places.  TINYINT: up to 4 digit number without decimal.  MEDIUMINT: up to 9 digit number without decimal.  BIGINT: up to 11 digit number without decimal.  DOUBLE(M.D): A Double precision floating numbers up to M digit with D decimal places.default to 16,4

Date & Time Data Types  DATE : A date in YYYY-MM-DD format, between and example: December 30 th,1973 would be stored as  DATETIME:A date and time format like YYYY- MM-DD HH:MM:SS. Example: :3:00  TIME :Stores time in HH:MM:SS format.  YEAR(M): Store a year in 2 or 4 digits format. Example:  YEAR(2), year can be 1970 to 2069(70 to 69).

String /text Types:  CHAR(M):A fixed length string up to 255 characters. (default is 1)  VARCHAR(M):A variable length string up to 255 characters.  BLOB :Used to store image data or characters up to  TEXT: Same as BLOB but offers not case sensitive search. Difference between Char and Varchar data types  The difference between CHAR and VARCHAR is that of fixed length and variable length.  The CHAR data types specifies a fixed length character string and VARCHAR data types specifies a variable length string.

SQL Server Data Types  int, integer: 4 byte integer  smallint: 2 byte integer  tinyint: 1 byte integer  float: 4 or 8 byte floating point number  real: 4 byte floating point number  double precision: 8 byte floating point number  numeric, decimal(precision, scale): exact numeric, 2 to 17 bytes. Only difference is that only numeric types with a scale of 0 can be used of the IDENTITY column.  Destroy a table: drop table table_name

SQL COMMAND SYNTAX  The SQL provides a predefined set of commands that help us work on relational databases.  Keywords are words that have a special meaning in SQL. They are understood to be instructions.  Commands, or statements, are instructions given by you to a SQL database.  Arguments complete or modify the meaning of a clause.

SPECIAL OPERATORS  BETWEEN - define range limits  IS NULL - check if attribute value is null  LIKE - check for similar character strings  IN - check if attribute value matches a value within a (sub)set of listed values  EXISTS - check whether attribute has a value

Basic MySQL Operations  Create database  use database  see data base  Create table  Insert records  Load data  Retrieve records  Update records  Delete records  Modify table  Join table  Drop table  Optimize table  Count, Like, Order by, Group by  More advanced ones (sub-queries, stored procedures, triggers, views …)

 Some Data Management commands in MySQL  Creating a Database: Syntax to Create database: Create database databasename ;  The following command will create School database in MySQL. Ex. mysql> CREATE DATABASE School;  Opening a database: To open an existing database you can use the following command. Ex. mysql> USE school ; Database changed  What tables are currently stored in the MyDB database? mysql> show tables; Empty set (0.00 sec)

What are the current databases at the server? mysql> show databases; | Database | | mysql | | test | mysql is a database (stores users’ password) used by system.

 Creating a table in the database: To create a table we can use Create Table command. The following command will create Student table with Stname and Stcity columns.  Syntax;  CREATE TABLE (columnname datatypes[size], columnname data types[size],….); Ex. mysql> CREATE TABLE student (Stname char(30), Stcity char(20), age Integer );

Making Simple Queries  Inserting a Record in a table mysql> INSERT INTO Student VALUES (‘Amit’, ‘ Suratgarh’, 16);  Deleting a Table and database mysql> DROP TABLE Student ; mysql> DROP DATABASE School ;  Viewing Table Structure mysql> DESCRIBE Student ;  The SELECT command of SQL, empower you to make a request (queries) to retrieve records from the database.  The syntax of SQL is given below-  SELECT FROM WHERE ORDER BY [ASC | DESC] ;

 SELECT Statement: for queries on single or multiple tables  Clauses of the SELECT statement: –SELECT: List the columns (and expressions) that should be returned from the query –FROM: Indicate the table(s) or view(s) from which data will be obtained –WHERE: Indicate the conditions under which a row will be included in the result –GROUP BY: Indicate columns to group the results –HAVING: Indicate the conditions under which a group will be included –ORDER BY: Sorts the result according to specified columns

18

 Selecting From All the Rows-ALL Keyword: The result retains the duplicates output rows. It is just the same as when you specify neither DISTINCT nor ALL.  EXAMPLE:  SELECT ALL city FROM Student;

 Sorting by Column Alias  If you have defined column alias in your query, then you can use this column alias even for sorting records. This is because, once a column alias is declared, it can be used elsewhere in the statement.