IS 380 Introduction to SQL This lectures covers material from: database textbook chapter 3 Oracle chapter: 3,14,17.

Slides:



Advertisements
Similar presentations
1 SQL Server Management Studio SQL DDL CREATE TABLE Constraints ALTER TABLE DROP TABLE The GUI way Steen Jensen, autumn 2013.
Advertisements

7 7 SQL Data Definition 4Spread throughout chapter 7.
Database Systems: Design, Implementation, and Management Tenth Edition
Copyright © by Royal Institute of Information Technology Introduction To Structured Query Language (SQL) 1.
Introduction to Structured Query Language (SQL)
5 Chapter 5 Structured Query Language (SQL2) Revision.
Fundamentals, Design, and Implementation, 9/e COS 346 Day 11.
Introduction to Structured Query Language (SQL)
Structured Query Language (SQL)
SQL components In Oracle. SQL in Oracle SQL is made up of 4 components: –DDL Data Definition Language CREATE, ALTER, DROP, TRUNCATE. Creates / Alters.
3 3 Chapter 3 Structured Query Language (SQL) Database Systems: Design, Implementation, and Management 4th Edition Peter Rob & Carlos Coronel.
Fundamentals, Design, and Implementation, 9/e Chapter 6 Introduction to Structured Query Language (SQL)
A Guide to SQL, Seventh Edition. Objectives Understand the concepts and terminology associated with relational databases Create and run SQL commands in.
Creating Database Tables © Abdou Illia MIS Spring /21/2015.
Introduction to Structured Query Language (SQL)
SQL DDL constraints Restrictions on the columns and tables 1SQL DDL Constraints.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 7 Introduction to Structured Query Language (SQL)
Database Constraints. Database constraints are restrictions on the contents of the database or on database operations Database constraints provide a way.
Oracle Data Definition Language (DDL)
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
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.
Chapter 9 SQL and RDBMS Part C. SQL Copyright 2005 Radian Publishing Co.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor Ms. Arwa.
ORACLE SQL. Overview Personal DBMS Vs Client/Server DBMS Oracle 8 Environment SQL – syntax and examples PL/SQL-introduction.
Database Design lecture 3_1 1 Database Design Lecture 3_1 Data definition in SQL.
SQL data definition using Oracle1 SQL Data Definition using Oracle.
© 2007 by Prentice Hall (Hoffer, Prescott & McFadden) 1 Introduction to SQL.
Chapter 10 – Database Creation1 IT238: Data Modeling and Database Design Unit 6: Database Creation Instructor: Qing Yan, M.D., Ph.D.
SQL data definition using Oracle1 SQL Data Definition using Oracle.
Oracle Data Definition Language (DDL) Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
SQL SQL Server : Overview SQL : Overview Types of SQL Database : Creation Tables : Creation & Manipulation Data : Creation & Manipulation Data : Retrieving.
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.
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.
SQL: DDL. SQL Statements DDL - data definition language –Defining and modifying data structures (metadata): database, tables, views, etc. DML - data manipulation.
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.
1 DBS201: Introduction to Structure Query Language (SQL) Lecture 1.
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 7 Introduction to Structured Query Language (SQL)
1 Chapter 6 Structured Query Language (SQL) DATABASE MANAGEMENT SYSTEM.
Tables and Constraints Oracle PL/SQL. Datatypes The SQL Data Definition Language Commands (or DDL) enable us to create, modify and remove database data.
1 SQL - II Data Constraints –Applying data constraints Types of data constraints –I/O constraints The PRIMARY KEY constraints The FOREIGN KEY constraints.
Database Lab Lecture 1. Database Languages Data definition language ( DDL ) Data definition language –defines data types and the relationships among them.
CREATE TABLE CREATE TABLE statement is used for creating relations Each column is described with three parts: column name, data type, and optional constraints.
Prince Sultan University Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
DBSQL 5-1 Copyright © Genetic Computer School 2009 Chapter 5 Structured Query Language.
SQL – Structured Query Language
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
ITEC 3220A Using and Designing Database Systems Instructor: Prof. Z. Yang Course Website: 3220a.htm
1 Chapter 1 File Systems and Databases Database Systems: Design, Implementation, and Management, Fifth Edition, Rob and Coronel l 工程資料庫專題 –NTUST/ME-2007Q4.
Week 4 Lecture Part 2 of 3 Structured Query Language (SQL) Samuel ConnSamuel Conn, Faculty Suggestions for using the Lecture Slides.
Altering Tables and Constraints Database Systems Objectives Add and modify columns. Add, enable, disable, or remove constraints. Drop a table. Remove.
Relational Database Management System(RDBMS) Structured Query Language(SQL)
Starting with Oracle SQL Plus. Today in the lab… Connect to SQL Plus – your schema. Set up two tables. Find the tables in the catalog. Insert four rows.
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
Physical Model Lecture 11. Physical Data Model The last step is the physical design phase, In this phase data is – Store – Organized and – Access.
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.
Fundamentals of DBMS Notes-1.
SQL: Schema Definition and Constraints Chapter 6 week 6
Chapter # 7 Introduction to Structured Query Language (SQL) Part II.
SQL data definition using Oracle
Chapter 7 Introduction to Structured Query Language (SQL)
Oracle Data Definition Language (DDL)
Session - 6 Sequence - 1 SQL: The Structured Query Language:
Contents Preface I Introduction Lesson Objectives I-2
Chapter # 7 Introduction to Structured Query Language (SQL) Part I.
Presentation transcript:

IS 380 Introduction to SQL This lectures covers material from: database textbook chapter 3 Oracle chapter: 3,14,17

2 IS 380, A. M. Thomason Objective Understand the basics of database languages Learn how to manipulate and manage a database using SQL

3 IS 380, A. M. Thomason Structure query Language SQL meets ideal database language requirements: –SQL coverage fits into several categories: (1) Data Definition (DDL): Ex: Create Table (2) Data Management (DML).Ex: Delete (3) Data Query. (4) Transaction Control (5) Data Control Language (DCL) –SQL is relatively easy to learn. 4 th Gen. Language –ANSI prescribes a standard SQL.

4 IS 380, A. M. Thomason Why Study SQL? The ANSI standardization effort has led to a de facto query standard for relational databases. SQL has become the basis for present and expected future DBMS integration efforts. SQL has become the catalyst in the development of distributed databases and database client/server architecture.

5 IS 380, A. M. Thomason SQL Data Definition Data Management Data Query.

6 IS 380, A. M. Thomason Data Definition Create a database Create a Table columns names, data types Delete a table structure Modify a columns data type

7 IS 380, A. M. Thomason Data Management Insert New records Modify existing records delete records

8 IS 380, A. M. Thomason Query Allows you to ask the database questions or view the table from different perspectives and criterion without modifying the content.

9 IS 380, A. M. Thomason Creating Tables CREATE TABLE [user.]table (column datatype [DEFAULT expr] [column_constraint], … [table_constraint]); Rules: name can be no longer than 18 characters the name must start with a letter No spaces allowed Underscores are alright to use.

10 IS 380, A. M. Thomason Creating a Simple Table Create table t (fd_name1 fd_type, fd_name2 fd_type, …); Example: Create table customer (ssn char(9), customername char(30), customeraddress char(30), amount number(10,2));

11 IS 380, A. M. Thomason Data types Char(n) - SQL specific varchar(2) - Text field variable lengh date number(x,n) See page 1060 in Oracle book for Oracle specific

12 IS 380, A. M. Thomason Deleting a Table Drop Table t Example: drop table customer

13 IS 380, A. M. Thomason Deleting records but not definition Truncate table t Example: Truncate table customer

14 IS 380, A. M. Thomason Adding new attributes (Columns) Alter table t add (fx fd_type, fy fd_type); Example: alter table customer add (zip char(5), phone char(10));

15 IS 380, A. M. Thomason Modify column definition Alter table table_name modify (fl newtype, f2 new_type,…); Example: alter table customer modify (customername char(50));

16 IS 380, A. M. Thomason Display the table structure Describe t; Example: describe customer;

17 IS 380, A. M. Thomason Data Management- insert records Insert into t values (f1value, f2value,, …); insert into t (f1, f2,…) values (f1value, f2value,…);

18 IS 380, A. M. Thomason Data Management- delete Delete from t where [conditions];

19 IS 380, A. M. Thomason Data Management- Update update t set f1=newvalue, f2=newvalue where [conditions];

20 IS 380, A. M. Thomason Data Management- save and Undo Commit; saves your date rollback; undo, save to last last commit status

21 IS 380, A. M. Thomason Copy contents from one table to another Insert into to-tableselect * from from-table; insert into to-table (column1, column2, …) select column1, column2,… from from table;

22 IS 380, A. M. Thomason Data Queries-display records Select * from t; selects all records from table t Select * from t where [conditions]; Select * from t f1, f2, …. Where [conditions];

23 IS 380, A. M. Thomason Conditions Mathematical and logical operators = <> > < >= <=

24 IS 380, A. M. Thomason Conditions-continued Mathematical and logical operators and or not Example: ….where price > 10; where price is > 10 and code <> 1234;

25 IS 380, A. M. Thomason Nulls and Not Nulls –Nulls: Is used when the values for one or more columns are unknown. This is not the same as spaces. SQL handles the problem of not having a value by allowing this special value to represent an unknown or nonapplicable. It is known as a null data value. When defining the table structure it can be assigned. –Not nulls is used for such situations a a key field. Where you do want to make sure a value is entered.

26 IS 380, A. M. Thomason Constraints - advance Column Constraints column [CONSTRAINT constraint_name] constraint_type, Table Constraints [CONSTRAINT constraint_name] constraint_type (column, …), If constraint is a foreign key, follow this syntax: [FOREIGN KEY] (column, …) REFERENCES table [ (column, …) ] [ON DELETE CASCADE] Constraint Types: –NOT NULL –UNIQUE –PRIMARY KEY –FOREIGN KEY –CHECK

27 IS 380, A. M. Thomason Sample Tables VENDOR and PRODUCT 1:M relationship Some characteristics to note –The VENDOR table contains vendors who are not referenced in the PRODUCT table. PRODUCT is optional to VENDOR. –All V_CODE values in the PRODUCT table must have a match in the vendor table. –A few products are supplied factory-direct, a few are made in-house, and a few may have been bought in a special warehouse sale. That is, a product is not necessarily supplied by a vendor. VENDOR is optional to PRODUCT.

28 IS 380, A. M. Thomason CREATE TABLE VENDOR (VEN_CODEINTEGER, VEN_NAMEVARCHAR2(35) CONSTRAINT VENDOR_VEN_NAME_NN NOT NULL, VEN_CONTACTVARCHAR(15)CONSTRAINT VENDOR_VEN_CONTACT_NN NOT NULL, VEN_AREACODECHAR(3)CONSTRAINT VENDOR_VEN_AREACODE_NN NOT NULL, VEN_PHONECHAR(8)CONSTRAINT VENDOR_VEN_PHONE_NN NOT NULL, VEN_STATECHAR(2)CONSTRAINT VENDOR_VEN_STATE_NN NOT NULL, VEN_ORDERCHAR(1)CONSTRAINT VENDOR_VEN_ORDER_NN NOT NULL, CONSTRAINT VENDOR_VEN_CODE_PK PRIMARY KEY (VEN_CODE)); Create Table Examples - vendor Table

29 IS 380, A. M. Thomason CREATE TABLE PRODUCT (PROD_CODEVARCHAR(10), PROD_DESCRIPTVARCHAR(35)CONSTRAINT PRODUCT_PROD_DESCRIPT_NN NOT NULL, PROD_INDATEDATECONSTRAINT PRODUCT_PROD_INDATE_NN NOT NULL, PROD_ONHANDINTEGERCONSTRAINT PRODUCT_PROD_ONHAND_NN NOT NULL, PROD_MININTEGERCONSTRAINT PRODUCT_PROD_MIN_NN NOT NULL, PROD_PRICENUMBER(8,2)CONSTRAINT PRODUCT_PROD_PRICE_NN NOT NULL, PROD_DISCOUNTNUMBER(4,1)CONSTRAINT PRODUCT_PROD_DISCOUNT_NN NOT NULL, VEN_CODEINTEGER, CONSTRAINT PRODUCT_PROD_CODE_PK PRIMARY KEY (PROD_CODE), CONSTRAINT PRODUCT_VENDOR_VEN_CODE_FK FOREIGN KEY (VEN_CODE) REFERENCES VENDOR); Create Table Examples - Product Table

30 IS 380, A. M. Thomason Additional SQL commands Between like Order by Views In Null Union, Intersect, Minus (Page 292 in Oracle book)

31 IS 380, A. M. Thomason Between Select pnum from product where price between 10 and 20;

32 IS 380, A. M. Thomason Like Compares to similar character string % represents any group of characters _ represents one character Ex: … where name like ‘s%’; ….where name like ‘_llen’;

33 IS 380, A. M. Thomason Like Compares to similar character string % represents any group of characters _ represents one character Ex: … where name like ‘s%’; ….where name like ‘_llen’;

34 IS 380, A. M. Thomason Order by Default is ascending … order by f1; For descending: ….order by f1 desc;

35 IS 380, A. M. Thomason Views A definition of a restricted portion of a table. Create view accounting as select column1 column2 where price < 100 from Payroll;

36 IS 380, A. M. Thomason In Select employee payrollno phone from accounting where department in (‘IS’, ‘Purchasing’, ‘Benefits’); The statement above selects those employees who work in either IS, Purchasing or benefits. You may also use not in.

37 IS 380, A. M. Thomason Null Select employee payroll phone from accounting where department is not null; Select employee payroll phone from accounting where department is null; The following would be incorrect Select employee payroll phone from accounting where department =null;.