Lecture by Prof.Dr.S.Sridhar 1 DataBase Technology by Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany) DIRECTOR ARUNAI ENGINEERING.

Slides:



Advertisements
Similar presentations
COP4540 Database Management System Midterm Review
Advertisements

Chapter 10: Designing Databases
Database Administration, Integrity and Performance.
Relational Database. Relational database: a set of relations Relation: made up of 2 parts: − Schema : specifies the name of relations, plus name and type.
Chapter 3 An Introduction to Relational Databases.
Database Management: Getting Data Together Chapter 14.
The Relational Database Model:
3-1 Chapter 3 Data and Knowledge Management
A Guide to SQL, Seventh Edition. Objectives Understand the concepts and terminology associated with relational databases Create and run SQL commands in.
Concepts of Database Management Sixth Edition
Chapter 4 Relational Databases Copyright © 2012 Pearson Education, Inc. publishing as Prentice Hall 4-1.
Databases and Database Management Systems
Mgt 20600: IT Management & Applications Databases Tuesday April 4, 2006.
Chapter 4 Relational Databases Copyright © 2012 Pearson Education 4-1.
Introduction To Databases IDIA 618 Fall 2014 Bridget M. Blodgett.
Introduction Chapter 1. Reference Book  Database Systems Thomas Connolly, Carolyn Begg, Anne Strachan Addison-Wesley 1999 ISBN:
Introduction to DBMS and SQL Introduction to DBMS and SQL GUIDED BY : MR. YOGESH SAROJ (PGT-CS) MR. YOGESH SAROJ (PGT-CS) Presented By : JAYA XII –COM.
Database Lecture # 1 By Ubaid Ullah.
CS370 Spring 2007 CS 370 Database Systems Lecture 2 Overview of Database Systems.
 Introduction Introduction  Purpose of Database SystemsPurpose of Database Systems  Levels of Abstraction Levels of Abstraction  Instances and Schemas.
RAJIKA TANDON DATABASES CSE 781 – Database Management Systems Instructor: Dr. A. Goel.
6.8 Case Study: E-R for Supplier-and-Parts Database
An Overview of Database Management
Chapter 1 Overview of Database Concepts Oracle 10g: SQL
Chapter 4 The Relational Model 3: Advanced Topics Concepts of Database Management Seventh Edition.
1 INTRODUCTION TO DATABASE MANAGEMENT SYSTEM L E C T U R E
1 Introduction to Database Systems. 2 Database and Database System / A database is a shared collection of logically related data designed to meet the.
Summary Data Modeling SDLC What is Data Modeling Application Audience and Services Entities Attributes Relationships Entity Relationship Diagrams Conceptual,Logical.
Concepts and Terminology Introduction to Database.
CS 474 Database Design and Application Terminology Jan 11, 2000.
1 Welcome: To the second learning sequence “ Data Base (DB) and Data Base Management System (DBMS) “ Recap : In the previous learning sequence, we discussed.
Lecture 2 An Overview of Relational Database IST 318 – DB Admin.
CODD’s 12 RULES OF RELATIONAL DATABASE
1 Structured Query Language (SQL) CIS*2450 Advanced Programming Concepts.
Logical Database Design ( 補 ) Unit 7 Logical Database Design ( 補 )
Chapter 10 Views. Topics in this Chapter What are Views For? View Retrievals View Updates Snapshots SQL Facilities.
DAY 12: DATABASE CONCEPT Tazin Afrin September 26,
Lecture2: Database Environment Prepared by L. Nouf Almujally & Aisha AlArfaj 1 Ref. Chapter2 College of Computer and Information Sciences - Information.
1 Chapter 1 Introduction. 2 Introduction n Definition A database management system (DBMS) is a general-purpose software system that facilitates the process.
“INTRODUCTION TO DATABASE AND SQL”. Outlines 2  Introduction To Database  Database Concepts  Database Properties  What is Database Management System.
Instructor: Dema Alorini Database Fundamentals IS 422 Section: 7|1.
Lecture2: Database Environment Prepared by L. Nouf Almujally 1 Ref. Chapter2 Lecture2.
Relational Database. Database Management System (DBMS)
Lecture # 3 & 4 Chapter # 2 Database System Concepts and Architecture Muhammad Emran Database Systems 1.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
INFO1408 Database Design Concepts Week 15: Introduction to Database Management Systems.
Copyright 2006 Prentice-Hall, Inc. Essentials of Systems Analysis and Design Third Edition Joseph S. Valacich Joey F. George Jeffrey A. Hoffer Chapter.
Lecture No 14 Functional Dependencies & Normalization ( III ) Mar 04 th 2011 Database Systems.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Introduction to database system What is a Database system? What is a Database system? Data System Components Data System ComponentsDataHardwareSoftwareUser.
Programming Logic and Design Fourth Edition, Comprehensive Chapter 16 Using Relational Databases.
INTRODUCTION lecture1 1. Data base concept Data is a meaningless static value. What does 3421 means? Information is the data you process in a manner that.
The relational model A data model (in general) : Integrated collection of concepts for describing data (data requirements). Relational model was introduced.
Chapter 10 Designing Databases. Objectives:  Define key database design terms.  Explain the role of database design in the IS development process. 
1 MySQL and SQL. 2 Topics  Introducing Relational Databases  Terminology  Managing Databases MySQL and SQL.
King saud university Introduction to Database Systems (Chapter 1: Databases and Database Users)
Data The fact and figures that can be recorded in system and that have some special meaning assigned to it. Eg- Data of a customer like name, telephone.
Database System Concepts Introduction Purpose of Database Systems View of Data Data Models Data Definition Language Data Manipulation Language Transaction.
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
SQL Basics Review Reviewing what we’ve learned so far…….
Rationale Databases are an integral part of an organization. Aspiring Database Developers should be able to efficiently design and implement databases.
1 CS122A: Introduction to Data Management Lecture #4 (E-R  Relational Translation) Instructor: Chen Li.
1 Section 1 - Introduction to SQL u SQL is an abbreviation for Structured Query Language. u It is generally pronounced “Sequel” u SQL is a unified language.
Translation of ER-diagram into Relational Schema
Introduction lecture1.
پايگاه داده ها.
Φροντιστήριο SQL (από το βιβλίο του Date)
Database Design: Relational Model
INTRODUCTION A Database system is basically a computer based record keeping system. The collection of data, usually referred to as the database, contains.
Presentation transcript:

Lecture by Prof.Dr.S.Sridhar 1 DataBase Technology by Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany) DIRECTOR ARUNAI ENGINEERING COLLEGE TIRUVANNAMALAI

Lecture by Prof.Dr.S.Sridhar 2 DBMS CONCEPTS Data Base Management Systems Examples of Databases Files & DB – Systems Advantages of DBMS Attributes / Entities Normalization in RDBMS RDBMS & Examples SQL in DB & Examples Entity-relationship model 3NF Students/s DB – Case Study Data Base Security / Backups

Lecture by Prof.Dr.S.Sridhar 3 What’s Database System ? - It is nothing but a computerized record keeping system. - The DB itself can be regarded as electronic filing cabinet. - It is a collection of files. The user of the system will have the following facilities : Adding New, empty files to the DB. Inserting new data into existing files. Retrieving data from existing files. Deleting data from existing files. Removing existing files, empty or otherwise, from the DB Data base is a collection of files. Data base is a collection of records. Data base is a collection of fields.

Lecture by Prof.Dr.S.Sridhar 4 The above file is referred as ‘Table’ in RDBMS – Sense. Call this table as “CELLAR” This contains many records. Each record has fields. Here is a record The values inside the table are called “ Field values” BI N WINEPRODUCERYEARBOTTLE S REA DY 2ChardonnaryBuena Vista ChardonnaryGeyser Peak ChardonnaryStonestreet Jo.RieslingJekel Fune ‘ BlancCh.St.Jean Fune ‘ BlancGeyser Peak Cab.Saurigno n Jekel Cab.Saurigno n Jekel Pinot NoirBuena Vista Pinrot NoirBuena Vista BI N WIN E PRODUC ER YEA R BOTTLE S READ Y Fields

Lecture by Prof.Dr.S.Sridhar 5 Retrieve Data (Query Language) SELECT WINE, BIN, PRODUCER FROM CELLAR WHERE READY = 1995 ; RESULT is the command used to Retrive from which table ( file ) Condition INSERT: INSERT INTO CELLAR ( BIN, WINE, PRODUCER ) VALUES ( 53, ‘Pinot Noir’, ‘Saintsbury’); UPDATE: UPDATE CELLAR SET BOTTLES = 4 WHERE BIN = 3; WINE Cab.Saurig non BIN 30 PRODUCER JEKEL

Lecture by Prof.Dr.S.Sridhar 6 DELETE FROM CELLAR WHERE BIN = 2; Thus, the commands like, SELECT, INSERT, UPDATE and DELETE are actually the examples of Database Query Language. SQL – Structured Query Language Remarks : - One should be very careful. Whenever DELETE or UPDATE operations are done in the DB. Here, - Retrieving any amount of fields for a particular record is done. - Inserting into file for a particular field(s) with values is done. - Updating is for a particular field in a record is done. - Deleting is done for a record under a matching condition.

Lecture by Prof.Dr.S.Sridhar 7 (DBMS) Data Base Management System Application END Programs USERS Major Components: * Data * HardwareSimplified View * Software of Data base System * Users An Overview of Database Management Data Base

Lecture by Prof.Dr.S.Sridhar 8 Examples of Data Bases:  Financial Database  Personnel Database ( Employee)  Payroll Database  Accounting Database  Inventory Database  Management Information Database  Library Database and so on. Examples of DBMS (Data Base Management System)  ORACLE  INFORMIX  INGRESS  SYBASE and so on. What ‘s Data ? It is the meaning full information stored in computer system. Two Kinds  Integrated  Shared Integrated, means that the Database can be thought of as a unification of several otherwise distinct data files, with any redundancy among those files wholly or partially.

Lecture by Prof.Dr.S.Sridhar 9 Example A Database containing both the files. EMPLOYEE IDNO Name Address Department Salaries Phone No. Permanent Address and a training file. TRAINING IDNO Course a Headed Course Details Course Fees Location of Course Feedback Grade Offered Shared Database means that individual pieces of data in the database can be shared by several different users. For example from the file ‘EMPLOYEE’, The general details can be utilised by Personnel department. The salary details may be utilized by Financial department. All done in shared manner. and so on.

Lecture by Prof.Dr.S.Sridhar 10 Hardware Consisting of  Secondary storage volumes that are used to hold the stored data with associated I/O devices(Disk drives etc), Devices Controllers, I/O channels,etc.  The Processors and associated main memory that are used to support the execution of the Database system software. Software Consisting of  Database Manager (DB Manager) or more commonly used term as ‘DBMS’, Data Base Management System.  Additional utilities like Application development tools, design aids, report writers and so on. Example: Oracle, Informix, Sybase,etc. Users  Application Programmers, who are responsible for writing programs to access the Database for Insert, Update, Delete, Query, Reports etc.  End users who are really accessing the database for queries / data entry / report generation etc.

Lecture by Prof.Dr.S.Sridhar 11 What is Database ?  It is a collection of ‘Persistent data’ that is used by the application systems of some given enterprise.  Input data : refers the information entered into the systems for the very first time ( typically from a terminal or workstation). It may be part of persistent data but it is not initially part of the databases  Output Data : refers for messages and results coming out from the system ( typically printed or displayed on a screen). Again such information is derived from persistent data but it is not itself considered to the part of the database. Enterprise (Egs)Persistent Data (Egs) ****************************  A Manufacturing * Product Data Company  A Bank* Account Data  A Hospital* Patient Data  A University  A govt. Dept.

Lecture by Prof.Dr.S.Sridhar 12 Advantages of Databases  Compactness ( No read for Voluminous papers)  Speed ( for retrieval of Queries / Reports etc)  Currency (Accurate, up-to-date information is available on demand anytime )  Centralized control of data. The foregoing benefits apply even more force in multi – user environment, of course, where the database is likely to be much larger and much more complex then in the single-user-case.  Redundancy of data can be avoided.  In consistency can be avoided to some extent.  The data can be shared by many users.  Standards can be enforced.  Security restrictions can be applied.  Integrity can be maintained.  Conflicting requirement can be balanced.

Lecture by Prof.Dr.S.Sridhar 13 RDBMS (Relational Data Base Mgmt. System) Relational Systems are such that 1. The data perceived by users as tables. 2. The operators are at users’ disposal.(eg) Data retrieval – are operators that qurerate new tables from old and those operators include atleast ‘SELECT’, PROJECT and JOIN. EXAMPLE : DEPT EMP DEPT#DNAMEBUDGET D1 D2 D3 Marketing Development Research 10M 12M 5M EMP # ENAMEDEPTSalary E1 E2 E3 E4 John Marsal Lemark Cheng D1 D2 40k 25k 42k 35k

Lecture by Prof.Dr.S.Sridhar 14 SELECT – Operation extracts specified rows from a table. PROJECT - Operation extracts specified columns from a table JOIN - Operation joins together two tables on the basis of common values in a common column. Apply the above operations on DEPT & EMP Tables SELECT DEPTs WHERE BUDGET > 8M Result (Specified Rows) PROJECT DEPTs OVER DEPT#, BUDGET Result (Specified Columns) JOIN DEPTs and EMPs OVER DEPT# Result Common Rows Common Columns DEPT#DNAMEBUDGET D1 D2 Marketing Development 10M 12M DEPT#BUDGET D1 D2 D3 10M 12M 5M DEP T# DNAMEBUD GET EM P# ENAM E SAL D1 D2 Marketing Development 10M 12M E1 E2 E3 E4 John Marsal Lemark Cherq 40K 25K 42K 35K

Lecture by Prof.Dr.S.Sridhar 15 Entity – Attributes –Relationship models ConceptInformationExamples Definition ENTITYA Distinguishable- Supplier object- Part - Person - Purchase Order and so on PROPERTYA piece of information- Supplier number to describe an entity- Shipment Qty - Person height - P.O.data etc. RELATIONSHIP An entity that serves to- Shipment interconnect 2 or more (Supplier-part) entities- Assignment (Emp-Dept.) Here Note 1) Shipment is RELATIONSHIP between supplier and part. R Similarly for Assignment. Supplier Part

Lecture by Prof.Dr.S.Sridhar 16 Entity / Relationship diagram (Example) -----* * * * * Entities : Department, Employee, Dependent Relations : Dept-Emp, Emp-dep Attributes : ( to employee) Emp#, Ename,Salary FirstMNLast (Group item) Department Dept-Emp Employee Emp Ename FirstMNLast Salary Emp-Dep Dependent

Lecture by Prof.Dr.S.Sridhar 17 Properties: Entities have properties : (Known as attributes). Take the case of Employee whose properties are Emp#, Ename and Salary. (all these are attributes). Simple a Composite: Emp# is simple But Ename contains First, MN and Last, three simple items groped together to address Ename. Such type of attributes are ‘Composite’. Key : It is one of the uniquely defined attributes. For eg. Emp# is unique and that is called ‘key’ to access the other properties of the entity employee, like Ename and Salary. Key Emp#EnameSalary

Lecture by Prof.Dr.S.Sridhar 18 Types of Relations 1 – 1 (One to One) 1 – M (One to Many) M – 1(Many to One) M – M )(Many to Many) Examples ( 1-1) For every employee there is only one seat R (1-1) In an organization. (1-M) R ;. ; (M-1) R : ; (M – M) EmpSeat Supplier Customer1 Customer-m Student1 Student-m Teacher Suplier 1…….m Customer1 1………m

Lecture by Prof.Dr.S.Sridhar 19 Many Examples of Attributes / Entities & Relations Example 1: Book –Student BOOK-STD R > R R< STD -BOOK Entities : Book, Student Relation : BOOK-STD and STD-BOOK Attributes of BookAttributes of Student  Author  RollNo  Title  ExamNo  Publisher  Name  Year  Class  ISBN Number  Address  Number of pages  Phone No  Price  Remarks  Printer  Location of printing  Edition-Nature  Remarks Book Student

Lecture by Prof.Dr.S.Sridhar 20 Example 2 ( R ) Part-Sup ( R ) Sub-part ( R ) Entities : Part, Supplier Relations: Part-Sup and Sub-part Attributes of partAttributes of Supplier  PartNo  Supplier code  Description  Supplier address  Qty  Supplier phone  Unit price  Supplier location  Opening balance  Delivery time  Parts-new  Address demand  Net balance  Warranty Period  Remarks  Remarks Part Supplier

Lecture by Prof.Dr.S.Sridhar 21 Example 3: Stud-fac R Fac-stud Entities : Student and Faculty Relations : Stud-fac and Fac-stud Attributes of StudentAttributes of Faculty  RollNo  Facuty ID  ExamNo  Name  Name  Classes Handling  Class  Qualification  Address  Designation  PhoneNo  Address  Faculty Division  Phone No  Remarks  Students Related for Advising Student Faculty

Lecture by Prof.Dr.S.Sridhar 22 NORMALIZATION in RDBMS The logical design considered are: S ( S#, SNAME, STATUS, CITY) PRIMARY KEY ( S#) P (P#, PNAME,COLOR, WEIGHT, CITY) PRIMARY KEY (P#) SP (S#, p#,QTY) PRIMARY KEY (S#, P#) FOREIGN KEY ( S#) REFERENCE S FOREIGN KEY (P#) REFERENCE P SCP (Relation) Table S#CITYP#QTY S1 S2 S3 S4 London Paris London P1 P2 P3 P4 P5 P6 P1 P2 P4 P

Lecture by Prof.Dr.S.Sridhar 23 From the table we find ‘Redundancy’ of data. So a good design principle is “ One fact in one place” ((ie) avoid redundancy). How to do this ? That process is known as “ Normalization”. There are 3NF (Normal forms – NF). NamelyFirst NF (1NF) Second NF (2NF) Third NF (3NF) 1NF: Every Normalized relation is in 1NF if and only if, if satisfied the condition that it contains scalar values ONLY. Example FIRST (S#, STATUS, CITY, P#, QTY) PRIMARY KEY (S#, P#) Functional Dependencies in relation FIRST QTY CITY STATUS S# P#

Lecture by Prof.Dr.S.Sridhar 24 Sample Tabulation of FIRST Now problems, We face with  INSERT  DELETE  UPDATE S#STATUSCITYP#QTY S1 S2 S3 S London Paris London P1 P2 P3 P4 P5 P6 P1 P2 P4 P

Lecture by Prof.Dr.S.Sridhar 25 Problems with INSERT - For examples, while inserting S5 after S! or S2 or S3 or S4, Confusion arises, Where to insert ?! - Insert a status after 20 – problem ! - Insert a city after LONDON – problem ! - Insert P# after P2 – Problem ! DELETE While deleting some record, One should be more careful. Now delete a record corresponding to S# = 1. This will delete all records corresponding to S# = 1, whereas user may NOT mean this ! Similarly, UPDATE : Update city for S# = 2 This will update all city values, corresponding to S# = 2, whereas user does not mean this !

Lecture by Prof.Dr.S.Sridhar 26 Second Normal Form : A relation is in 2NF if and only if is in !NF and every non-key attribute is irreducibly dependent on the primary key. Example SECOND (S#, STATUS, CITY) and SP(S#, P#, OTY) Functional Dependencies in relation SECOND AND SP SECOND SAMPLE TABULATION OF SECOND AND SP CITY S# STATUS QTY S# P# S#StatusCity S1 S2 S3 S4 S London Paris London Athens S#P#QTY S1 S2 S3 S4 P1 P2 P3 P4 P5 P6 P1 P2 P4 P

Lecture by Prof.Dr.S.Sridhar 27 INSERT : Eventhough S5 is not supplying any parts, we can insert the information that S5 is located in Athens, in SECOND. DELETE : While deleting the shipment connecting S3 and P2 in SP, we do NOT loose information that S3 is located in PARIS. UPDATE : In the revised structure, the city for given supplier appears once not many times. Thus S# CITY redundancy is eliminated. For example we can change for S1, the city as Amsterdam from London. This way updation is also possible in 2NF. Third Normal Form (3NF): A relation is in 3NF if it is in 2NF and every non-key attribute is non-transitively dependent on the primary key. This increases the data independance,.

Lecture by Prof.Dr.S.Sridhar 28 Example:Key Sample Tabulation of SC and CS The above relation SC and CS are in 3NF. Whereas, SECOND is not in 3NF. SECOND Thus SECOND (S#, STATUS, CITY) is tabulated in 3NF as SC(S#, CITY) and CS (CITY, STATUS) S#CITY S1 S2 S3 S4 S5 London Paris London Athens CITYSTATUS Anthen London Paris Rome S#STATUSCITY S1 S2 S3 S4 S London Paris London Athens

Lecture by Prof.Dr.S.Sridhar 29 Database Security & Back-ups Security problems :  Legal, Social and ethical aspects Eg : does a person making the request say for customer’s credit - have a legal right to the requested information.  Physical Controls Eg : Computer or Terminal room locked ! Or otherwise guarded ? !  Policy Questions Who should have access ? ! To what level ? !  Operational Problems - Password is used. Then - How are the passwords Rept secrete ? - How often they are changed ?

Lecture by Prof.Dr.S.Sridhar 30 Hardware Control - Whether the processing unit has any security measures,such as storage protection keys or privileged operation mode ? Operating System Security - Whether the O /S erase the contents of storage ? ! and Data files ? ! Issues Concerned with DBMS - Whether the DBMS has the concept of ownership ? Examples of Discretionary Access control Create Security Rule SR3 GRANT RETRIEVE (S#, SNAME, CITY), DELETE ON S WHERE S.CITY = ‘LONDON’ TO JIM, FRED, MARY ON ATTEMPTED VIOLATION REJECT;

Lecture by Prof.Dr.S.Sridhar 31  CREATE SECURITY RULE EX1: GRANT RETRIVE (S#, SNAME, CITY) ON S TO JAC, ANNE, CHARLEY;  CREATE SECURITY RULE EX4: GRANT RETRIVE (S#, SNAME) ON S WHERE S. STATUS > 50 TO JAC, PAVL;  CREATE VIEW SSS AS (S.S#, S.NAME) WHERE S.STATUS > 50; Request Modification :  DEFINE PERMIT RETRIEVE ON P TO U WHERE P.CITY = “London”  RETRIEVE (P.P#, P.WEIGHT) WHERE P.COLOR = “Red”  RETRIEVE (P.P#, P.WEIGHT) WHERE P.CITY = “London”

Lecture by Prof.Dr.S.Sridhar 32 Back – ups:  Daily Back-up After the day work of all transactions, copying the entire system files / data files on a floppy, disk (CD), or a tape depending on the size of total volume.  Weekly back-up  Monthly back-up  Yearly back-up  In DBMS – Mirroring concept as back –up.  Stand-by server as back-up  CD- Server as back –up  Software, specially in Oracle like RDBMS, auto back-up and retrieval systems.

Lecture by Prof.Dr.S.Sridhar 33 SQL – Language CREATE TABLE ( S# S# NOT NULL, P# P# NOT NULL, QTY QTY NOT NULL, PRIMARY KEY (S#) REFERENCE S ON DELETE CASECADE ON UPDATE CASCADE, CHECK(QTY > 0 AND QTY < 5001)); This is to create a table with attributes S#, P#, QTY, all NOT NULL values and the primary key is S# also, check the condition while creating the table itself whether QTY is > 0 and QTY < Here CASCADE is used as an Option. ALTER TABLE S ADD COLUMN DISCOUNT INTEGER DEFAULT – 1; Here we can alter the table S by adding a new column namely DISCOUNT which is an integer quantity with default value = -1.

Lecture by Prof.Dr.S.Sridhar 34 DROP TABLE S; This will drop the created table S from the database. Data Manipulation (Retrieval operations) (called DML) SELECT P.COLOR, P.CITY FROM P WHERE P.CITY ’PARIS’ AND P.WEIGHT > 10; SELECT DISTINCT P.COLOR, P.CITY FROM P WHERE P.CITY ‘PARIS’ AND P.WEIGHT > 10; SELECT P.COLOR, P.CITY FROM P WHERE P.CITY ’PARIS’ AND P.WEIGHT > 10; ORDER BY CITY DESC;

Lecture by Prof.Dr.S.Sridhar 35 SELECT P.P#, P.WEIGHT * 454 AS GMNT From P; SELECT * FROM S; SELECT S.S#, S.NAME, S.STATUS, S.CITY, P.P#, P.NAME, P.COLOR, P. WEIGHT, FROM S, P WHERE S.CITY = P.CITY; S JOIN P USING CITY SELECT DISTINCT S.CITY AS SCITY, P. CITY AS PCITY FROM S JOIN SP USING S# JOIN P USING P#; SELECT COUNT(*) AS NFROM S; SELECT MAX (SP.QTY)AS MAXQ, MIN (SP.QTY)AS MINQ FROM SP WHERE SP.P# = ‘P2’;

Lecture by Prof.Dr.S.Sridhar 36 Update Operations INSERT INTO P (P#, PNAME, COLOR, CITY) VALUES (‘P8’, ‘Sprocket’,’pink’, ‘Nice’); INSERT INTO TEMP(S#, CITY) SELECT S.S#, S.CITY FROM S WHERE S.STATUS > 15; DELETE FROM SP WHERE ‘London’ = (SELECT S.CITY FROM S WHERE S.S# = SP. S#); All or Any conditions SELECT DISTINCT PX.NAME FROM P AS PX WHERE PX.WEIGHT > ALL ( SELECT PY.WEIGHT FROM P AS PY WHERE PY.COLOR = ‘Blue’);

Lecture by Prof.Dr.S.Sridhar 37 Exercises ON SQL 1)CREATE TABLE ( S# S# NOT NULL, P# P# NOT NULL, QTY QTY NOT NULL) Ans 2) CREATE TABLE ( S# S# NOT NULL, P# P# NOT NULL, QTY QTY NOT NULL) PRIMARY KEY (S#) REFERENCE S CHECK (QTY >0 NAD QTY <= 20)); Ans S#P#QTY S#P#QTY

Lecture by Prof.Dr.S.Sridhar 38 3) ALTER TABLE S ADD COLUMN DISCOUNT INTEGER DEFAULT –1; Ans 4) DROP TABLE S; ( Then the table S will NOT be in DB) DATA MANIPULATION 1) SELECT S.P#, S.QTY FROM S WHERE S.QTY 20 AND S.P# > 500 ; Ans 2) SELECT DISTINCT S.S#, S.P#, S.QTY FROM S WHERE S.QTY 20 AND S,P# > 500; Ans S#P#QtyDiscount S#P#QTY S#P#QTY

Lecture by Prof.Dr.S.Sridhar 39 3) SELECT DISTINCT S.S#, S.P#, S.QTY S. Discount FROM S WHERE S.QTY < 5 AND S,P# > 125 ORDER BY S# DESC; Ans 4) SELECT S.S#, S.P#, S.QTY * 10 AS QTY2 FROM S WHERE DISCOUNT > 0; Ans 5) SELECT * FROM S; Ans S#P#QTYDiscount S#P#QTYQTY S#P#QtyDiscount

Lecture by Prof.Dr.S.Sridhar 40 6) SELECT S.S#, S.P#, S.QTY, P. P#, P.NAME FROM S, P WHERE S.P# = P.P# ; SAns ( input)  Answer 7)S JOIN P USING P# Answer is the same as 6..X. in this case only S#P#QtyDiscount P#PNAME NUT BOLT SCREEN ROD S.S#S.P#S.QTY P#PNAME NUT ROD SCREEN

Lecture by Prof.Dr.S.Sridhar 41 8) SELECT COUNT ( * ) AS N FORM S; Ans Count = N = 4 9) SELECT MAX ( S.QTY) AS MAXQ, MIN (S.QTY) AS MINQ FROM S WHERE S. DISCOUNT = -1; Answer MAXQ = 40 MINQ = 10 10) UPDATE Operations: INSERT INTO P ( P#, PNMAE) VALUES (4536, ‘STRING’); ? Ans  DELETE FROM P WHERE P.PNAME = ‘ROD’; P#PNAME NUT BOLT SCREEN ROD STRING P#PNAME NUT BOLT SCREEN STRING