ASSIGNMENT NO Computer System with Open Source Operating System. 2. Mysql

Similar documents
Exact Numeric Data Types

Unit 1 - Chapter 4,5

Database Management Systems,

Tranquility Publications. Web Edition MAC

SQL - QUICK GUIDE SQL - OVERVIEW

T- SQL Lab Exercises and Examples

CS 582 Database Management Systems II

CSC Web Programming. Introduction to SQL

SQL Joins and SQL Views

RDBMS. SQL is Structured Query Language, which is a computer language for storing, manipulating and retrieving data stored in a relational database.

Querying Data with Transact SQL

Data Manipulation Language (DML)

Database Systems: Design, Implementation, and Management Tenth Edition. Chapter 7 Introduction to Structured Query Language (SQL)

Introduction to SQL. SQL is a standard language for accessing and manipulating databases. What is SQL?

Based on the following Table(s), Write down the queries as indicated: 1. Write an SQL query to insert a new row in table Dept with values: 4, Prog, MO

Structure Query Language (SQL)

Unit Assessment Guide

Chapter-14 SQL COMMANDS

Advance SQL: SQL Performance Tuning. SQL Views

Oracle Database 11g: SQL and PL/SQL Fundamentals

About the Tutorial. Audience. Prerequisites. Compile/Execute SQL Programs. Copyright & Disclaimer SQL

INDEX. 1 Basic SQL Statements. 2 Restricting and Sorting Data. 3 Single Row Functions. 4 Displaying data from multiple tables

Database Management Systems,

CS3DB3/SE4DB3/SE6M03 TUTORIAL

WHAT IS SQL. Database query language, which can also: Define structure of data Modify data Specify security constraints

Oracle Database: SQL and PL/SQL Fundamentals NEW

Querying Data with Transact-SQL

Oracle Database: SQL and PL/SQL Fundamentals Ed 2

Chapter 3: Introduction to SQL. Chapter 3: Introduction to SQL

Chapter 3: Introduction to SQL

Introduction to SQL Part 2 by Michael Hahsler Based on slides for CS145 Introduction to Databases (Stanford)

Chapter 3: Introduction to SQL

Chapter 7. Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel

SQL functions fit into two broad categories: Data definition language Data manipulation language

Querying Data with Transact SQL Microsoft Official Curriculum (MOC 20761)

The SQL data-definition language (DDL) allows defining :

Ian Kenny. November 28, 2017

ASSIGNMENT NO 2. Objectives: To understand and demonstrate DDL statements on various SQL objects

20461: Querying Microsoft SQL Server 2014 Databases

Subquery: There are basically three types of subqueries are:

STRUCTURED QUERY LANGUAGE (SQL)

Data about data is database Select correct option: True False Partially True None of the Above

Database: Collection of well organized interrelated data stored together to serve many applications.

1. SQL Overview. Allows users to access data in the relational database management systems.

Oracle Database 10g: Introduction to SQL

2) SQL includes a data definition language, a data manipulation language, and SQL/Persistent stored modules. Answer: TRUE Diff: 2 Page Ref: 36

Lab # 6. Data Manipulation Language (DML)

MANAGING DATA(BASES) USING SQL (NON-PROCEDURAL SQL, X401.9)

Set theory is a branch of mathematics that studies sets. Sets are a collection of objects.

About the Tutorial. Audience. Prerequisites. Compile/Execute SQL Programs. Copyright & Disclaimer SQL

COURSE OUTLINE MOC 20461: QUERYING MICROSOFT SQL SERVER 2014

T-SQL Training: T-SQL for SQL Server for Developers

Test Bank for Database Processing Fundamentals Design and Implementation 13th Edition by Kroenke

Sun Certified MySQL Associate

UNIT-3. The entity-relationship model (or ER model) is a way of graphically representing the

Part I: Structured Data

Institute of Aga. Network Database LECTURER NIYAZ M. SALIH

SQL STRUCTURED QUERY LANGUAGE

Lecture 06. Fall 2018 Borough of Manhattan Community College

COMP 244 DATABASE CONCEPTS & APPLICATIONS

II B.Sc(IT) [ BATCH] IV SEMESTER CORE: RELATIONAL DATABASE MANAGEMENT SYSTEM - 412A Multiple Choice Questions.

STIDistrict Query (Basic)

Advanced SQL Tribal Data Workshop Joe Nowinski

What Are Group Functions? Reporting Aggregated Data Using the Group Functions. Objectives. Types of Group Functions

SQL. Char (30) can store ram, ramji007 or 80- b

ITCertMaster. Safe, simple and fast. 100% Pass guarantee! IT Certification Guaranteed, The Easy Way!

Full file at

Aggregation. Lecture 7 Section Robb T. Koether. Hampden-Sydney College. Wed, Jan 29, 2014

Querying Data with Transact-SQL

Oracle Syllabus Course code-r10605 SQL

Relational Algebra. Procedural language Six basic operators

After completing this course, participants will be able to:

Lecture 6 - More SQL

20461: Querying Microsoft SQL Server

Querying Microsoft SQL Server (MOC 20461C)

Principles of Data Management

Sql Server Syllabus. Overview

Querying Microsoft SQL Server 2012/2014

ITCertMaster. Safe, simple and fast. 100% Pass guarantee! IT Certification Guaranteed, The Easy Way!

Institute of Aga. Microsoft SQL Server LECTURER NIYAZ M. SALIH

SIT772 Database and Information Retrieval WEEK 6. RELATIONAL ALGEBRAS. The foundation of good database design

Relational Algebra Part I. CS 377: Database Systems

DATABASE MANAGEMENT SYSTEMS PREPARED BY: ENGR. MOBEEN NAZAR

AVANTUS TRAINING PTE LTD

Database design process

Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications. Administrivia. Administrivia. Faloutsos/Pavlo CMU /615

Course Modules for MCSA: SQL Server 2016 Database Development Training & Certification Course:

Computing for Medicine (C4M) Seminar 3: Databases. Michelle Craig Associate Professor, Teaching Stream

1 Writing Basic SQL SELECT Statements 2 Restricting and Sorting Data

Structure Query Language (SQL)

Intermediate SQL: Aggregated Data, Joins and Set Operators

Visit for more.

SQL Queries. COSC 304 Introduction to Database Systems SQL. Example Relations. SQL and Relational Algebra. Example Relation Instances

Querying Microsoft SQL Server

COURSE OUTLINE: Querying Microsoft SQL Server

Querying Microsoft SQL Server

Why Relational Databases? Relational databases allow for the storage and analysis of large amounts of data.

QQ Group

Carnegie Mellon Univ. Dept. of Computer Science Database Applications. General Overview - rel. model. Overview - detailed - SQL

Fundamentals of Database Systems

Transcription:

ASSIGNMENT NO. 3 Title: Design at least 10 SQL queries for suitable database application using SQL DML statements: Insert, Select, Update, Delete with operators, functions, and set operator. Requirements: 1. Computer System with Open Source Operating System. 2. Mysql Theory: Data Manipulation Language (DML) Statements : Data manipulation language (DML) statements access and manipulate data in existing schema objects. These statements do not implicitly commit the current transaction. The SELECT statement is a limited form of DML statement in that it can only access data in the database. It cannot manipulate data in the database, although it can operate on the accessed data before returning the results of the query. The data manipulation language statements are: INSERT, UPDATE, DELETE, SELECT The SELECT statement is a limited form of DML statement in that it can only access data in the database. It cannot manipulate data in the database, although it can operate on the accessed data before returning the results of the query. The SQL INSERT INTO Statement is used to add new rows of data to a table in the database. Syntax: There are two basic syntax of INSERT INTO statement as INSERT INTO TABLE_NAME (column1, column2, column3, columnn)] VALUES (value1, value2, value3, valuen);

Here, column1, column2, columnn are the names of the columns in the table into which want to insert data. It s not required to specify the column(s) name in the SQL query if values for all the columns of the table are provided. But make sure the order of the values is in the same order as the columns in the table. The SQL INSERT INTO syntax would be as INSERT INTO TABLE_NAME VALUES (value1,value2,value3, valuen); Following statements would create records in CUSTOMERS table: VALUES (1, Ramesh, 32, Ahmedabad, 2000.00 ); INSERT INTO CUSTOMERS VALUES (7, Muffy, 24, Indore, 10000.00 ); Populate one table using another table: You can populate data into a table through select statement over another table provided another table has a set of fields, which are required to populate first table. Here is the syntax: INSERT INTO first_table_name [(column1, column2, columnn)] SELECT column1, column2, columnn FROM second_table_name [WHERE condition]; SQL SELECT statement is used to fetch the data from a database table which returns data in the form of result table. These result tables are called result-sets. Syntax: The basic syntax of SELECT statement is as SELECT column1, column2, columnn FROM table_name; Here, column1, column2 are the fields of a table whose values you want to fetch. If you want to fetch all the fields available in the field, then you can use the following syntax:

SELECT * FROM table_name; SQL> SELECT ID, NAME, SALARY FROM CUSTOMERS; The SQL WHERE clause is used to specify a condition while fetching the data from single table or joining with multiple tables. If the given condition is satisfied then only it returns specific value from the table. You would use WHERE clause to filter the records and fetching only necessary records. The WHERE is also used in UPDATE, DELETE statement Syntax: The basic syntax of SELECT statement with WHERE clause is as SELECT column1, column2, columnn FROM table_name WHERE [condition] You can specify a condition using comparison or logical operators like >, <, =, LIKE, NOT, etc. SQL> SELECT ID, NAME, SALARY FROM CUSTOMERS WHERE SALARY > 2000; SQL> SELECT ID, NAME, SALARY FROM CUSTOMERS WHERE NAME = Hardik ; The SQL AND and OR operators are used to combine multiple conditions to narrow data in an SQL statement. These two operators are called conjunctive operators. These operators provide a means to make multiple comparisons with different operators in the same SQL statement. The AND Operator: The AND operator allows the existence of multiple conditions in an SQL statement s WHERE clause. Syntax: The basic syntax of AND operator with WHERE clause is as

SELECT column1, column2, columnn FROM table_name WHERE [condition1] AND [condition2] AND [conditionn]; You can combine N number of conditions using AND operator. For an action to be taken by the SQL statement, whether it be a transaction or query, all conditions separated by the AND must be TRUE. SQL> SELECT ID, NAME, SALARY FROM CUSTOMERS WHERE SALARY > 2000 AND age < 25; The OR Operator: The OR operator is used to combine multiple conditions in an SQL statement s WHERE clause. Syntax: The basic syntax of OR operator with WHERE clause is as SELECT column1, column2, columnn FROM table_name WHERE [condition1] OR [condition2] OR [conditionn] You can combine N number of conditions using OR operator. For an action to be taken by the SQL statement, whether it be a transaction or query, only any ONE of the conditions separated by the OR must be TRUE. SQL> SELECT ID, NAME, SALARY FROM CUSTOMERS WHERE SALARY > 2000 OR age < 25; The SQL UPDATE Query is used to modify the existing records in a table. You can use WHERE clause with UPDATE query to update selected rows otherwise all the rows would be affected. Syntax: The basic syntax of UPDATE query with WHERE clause is as UPDATE table_name SET column1 = value1, column2 = value2., columnn = valuen WHERE [condition]; You can combine N number of conditions using AND or OR operators. SQL> UPDATE CUSTOMERS SET ADDRESS = Pune WHERE ID = 6;

SQL> UPDATE CUSTOMERS SET ADDRESS = Pune, SALARY = 1000.00; The SQL DELETE Query is used to delete the existing records from a table. You can use WHERE clause with DELETE query to delete selected rows, otherwise all the records would be deleted. Syntax: The basic syntax of DELETE query with WHERE clause is as DELETE FROM table_name WHERE [condition]; You can combine N number of conditions using AND or OR operators. SQL> DELETE FROM CUSTOMERS WHERE ID = 6; If you want to DELETE all the records from CUSTOMERS table, you do not need to use WHERE clause and DELETE query would be as SQL> DELETE FROM CUSTOMERS; The SQL DISTINCT keyword is used in conjunction with SELECT statement to eliminate all the duplicate records and fetching only unique records. There may be a situation when you have multiple duplicate records in a table. While fetching such records, it makes more sense to fetch only unique records instead of fetching duplicate records. Syntax: The basic syntax of DISTINCT keyword to eliminate duplicate records is as SELECT DISTINCT column1, column2,..columnn FROM table_name WHERE [condition] SELECT DISTINCT SALARY FROM CUSTOMERS ORDER BY SALARY; The SQL GROUP BY clause is used in collaboration with the SELECT statement to arrange identical data into groups. The GROUP BY

clause follows the WHERE clause in a SELECT statement and precedes the ORDER BY clause. Syntax: The basic syntax of GROUP BY clause is given below. The GROUP BY clause must follow the conditions in the WHERE clause and must precede the ORDER BY clause if one is used. SELECT column1, column2 FROM table_name WHERE [ conditions ] GROUP BY column1, column2 SQL> SELECT NAME, SUM(SALARY) FROM CUSTOMERS GROUP BY NAME; Following is an example, which would sort the result in descending order by NAME: SQL> SELECT * FROM CUSTOMERS ORDER BY NAME DESC; SQL has many built-in functions for performing processing on string or numeric data. Following is the list of all useful SQL built-in functions: SQL SUM Function The SQL SUM aggregate function allows selecting the total for a numeric column. SQL COUNT Function The SQL COUNT aggregate function is used to count the number of rows in a database table. Syntax : SELECT COUNT(column_name) FROM table_name WHERE CONDITION; SQL MAX Function The SQL MAX aggregate function allows us to select the highest (maximum) value for a certain column. SQL MIN Function The SQL MIN aggregate function allows us to select the lowest (minimum) value for a certain column. SQL AVG Function The SQL AVG aggregate function selects the average value for certain table column.

Conclusion: Hence details about various DML commands and aggregate functions with GROUP BY clause are provided here. VALUES (2, Khilan, 25, Delhi, 1500.00 ); VALUES (3, kaushik, 23, Kota, 2000.00 ); VALUES (4, Chaitali, 25, Mumbai, 6500.00 ); VALUES (5, Hardik, 27, Bhopal, 8500.00 ); VALUES (6, Komal, 22, MP, 4500.00 ); Aggregate Functions Aggregate functions are functions that take a collection (a set or multiset) of values as input and return a single value. SQL offers five built-in aggregate functions: Average: avg Minimum: min

Maximum: max Total: sum Count: count The input to sum and avg must be a collection of numbers, but the other operators can operate on collections of nonnumeric data types, such as strings, as well. Basic Aggregation Consider the query Find the average salary of employees in the Computer Science department. We write this query as select avg (salary) from employee where dept name= Comp. Sci. ; The result of this query is a relation with a single attribute, containing a single tuple with a numerical value corresponding to the average salary of employees in the Computer Science department. We use the aggregate function count frequently to count the number of tuples in a relation. The notation for this function in SQL is count (*). Thus, to find the number of tuples in the employee relation, we write select count (*) from employee; There are circumstances where we would like to apply the aggregate function not only to a single set of tuples, but also to a group of sets of tuples; we specify this wish in SQL using the group by clause. The attribute or attributes given in the group by clause are used to form groups. Tuples with the same value on all attributes in the group by clause are placed in one group.

As an illustration, consider the query Find the average salary in each department. We write this query as select dept name, avg (salary) as avg salary from employee group by dept name; Set Operations The SQL operations union, intersect, and except operate on relations and correspond to the mathematical set-theory operations,, and. The Union Operation To find the set of all employees who belong to either IT dept. or Comp dept, or both, (select * from employee where dept_name= IT ) union (select * from employee where dept_name = Comp ); The union operation automatically eliminates duplicates, unlike the select clause. On the similar concepts, intersect and minus/except operations works by retaining their individual properties.