Lecture 7 – Database and SQL Database? A database is a collection of associated or related data. Examples – LIS (landuse information databse); Medical.

Slides:



Advertisements
Similar presentations
MySQL. To start go to Login details: login: labuser password:macimd15 – There.
Advertisements

SQL This presentation will cover: A Brief History of DBMS View in database MySQL installation.
Database Systems: Design, Implementation, and Management Tenth Edition
Fundamentals, Design, and Implementation, 9/e COS 346 Day 11.
Introduction to 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.
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.
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.
Oracle SQL*plus John Ortiz. Lecture 10SQL: Overview2 Overview  SQL: Structured Query Language, pronounced S. Q. L. or sequel.  A standard language for.
Attribute databases. GIS Definition Diagram Output Query Results.
Structured Query Language. Brief History Developed in early 1970 for relational data model: –Structured English Query Language (SEQUEL) –Implemented with.
Concepts of Database Management Sixth Edition
Chapter 3: SQL – Part I Yong Choi School of Business CSU, Bakersfield.
Microsoft Access 2010 Chapter 7 Using SQL.
Ceng 356-Lab1. Objectives After completing this lesson, you should be able to do the following: Get Familiar with the development environment List the.
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
Chapter 5 Introduction to SQL. Structured Query Language = the “programming language” for relational databases SQL is a nonprocedural language = the user.
Introduction to SQL Yong Choi School of Business CSU, Bakersfield.
ASP.NET Programming with C# and SQL Server First Edition
15 Structured Query Language (SQL). 2 Objectives After completing this section, you should be able to: Understand Structured Query Language (SQL) and.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor Ms. Arwa.
Concepts of Database Management Seventh Edition
1 Databases & SQL By: Julia Tartakovsky CS 340, Fall 2004 Acknowledgement (for help with the J# code connecting to an Oracle DB): Yosef Lifshits.
1 DATABASES & DATABASE MANAGEMENT SYSTEMS (DBMS). MS ACCESS What is a database Database terms DB constructing stages DB models Relational model Normal.
Structured Query Language. Brief History Developed in early 1970 for relational data model: –Structured English Query Language (SEQUEL) –Implemented with.
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
Chapter 7 SQL HUANG XUEHUA. SQL SQL server2005 introduction Install components  management studio.
NMED 3850 A Advanced Online Design January 12, 2010 V. Mahadevan.
SQL SQL Server : Overview SQL : Overview Types of SQL Database : Creation Tables : Creation & Manipulation Data : Creation & Manipulation Data : Retrieving.
Concepts of Database Management Seventh Edition
Unit 6 Data Storage Design. Key Concepts 1. Database overview 2. SQL review 3. Designing fields 4. Denormalization 5. File organization 6. Object-relational.
1 Information Retrieval and Use (IRU) CE An Introduction To SQL Part 1.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Chapter 10: The Data Tier We discuss back-end data storage for Web applications, relational data, and using the MySQL database server for back-end storage.
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.
A Guide to MySQL 3. 2 Introduction  Structured Query Language (SQL): Popular and widely used language for retrieving and manipulating database data Developed.
Chapter 8: SQL. Data Definition Modification of the Database Basic Query Structure Aggregate Functions.
SQL – Part I Yong Choi School of Business CSU, Bakersfield.
Concepts of Database Management Eighth Edition Chapter 3 The Relational Model 2: 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.
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.
NSF DUE ; Wen M. Andrews J. Sargeant Reynolds Community College Richmond, Virginia.
1 Copyright © Oracle Corporation, All rights reserved. Writing Basic SQL SELECT Statements.
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.
SQL: Structured Query Language It enables to create and operate on relational databases, which are sets of related information stored in tables. It is.
 CONACT UC:  Magnific training   
CS320 Web and Internet Programming SQL and MySQL Chengyu Sun California State University, Los Angeles.
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.
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
3 A Guide to MySQL.
Chapter 5 Introduction to SQL.
CS320 Web and Internet Programming SQL and MySQL
Insert, Update and the rest…
ATS Application Programming: Java Programming
ORACLE SQL Developer & SQLPLUS Statements
Chapter 7 Working with Databases and MySQL
SQL-1 Week 8-9.
Contents Preface I Introduction Lesson Objectives I-2
CS3220 Web and Internet Programming SQL and MySQL
CS3220 Web and Internet Programming SQL and MySQL
Structured Query Language Path from Unorganized to Organized….
Presentation transcript:

Lecture 7 – Database and SQL Database? A database is a collection of associated or related data. Examples – LIS (landuse information databse); Medical office database; tax database. Differences between database and file?

Database Models A conceptual way of thinking about data in a database is called a logical model. Over the past 30 years or so, 3 different logical database models have evolved: 1.The hierarchical model 2.The network model 3.The relational model

The relational Model Dr. Edgar F. Codd introduced the relational model around Idea: “If you ignore the way data files are connected and arrange your data into simple two-dimensional, unordered tables, then you can develop an algebra for queries and focus on the data as data, not as a physical realization of a logical model”

What is an ArcSDC Service? An ArcSDE service conveys spatial data between geographic information system applications and a database. The database may be any one of the supported RDBMSs: -Oracle -SQL Server -Informix

Applications The applications that can connect to and access spatial data from an ArcSDE service include ArcInfo, ArcView GIS, Map Objects, ArcIMS, and ArcSDE CAD client, as well as custom-built applications created by either you or an ESRI business partner.

Properties of an ArcSDE service The home directory – which is defined by the system variable, SDEHOME. The home directory – which is defined by the system variable, SDEHOME. The ArcSDE server monitor – the giomgr process The ArcSDE server monitor – the giomgr process The gsrvr process – dedicated to a single- user application connection. The gsrvr process – dedicated to a single- user application connection.

Properties of An ArcSDR service (Cont.) The TCP/IP servce name and port number – giomgr listens for application connection requests on a dedicated TCP/IP service name and port number The TCP/IP servce name and port number – giomgr listens for application connection requests on a dedicated TCP/IP service name and port number The database The database The configuration files – ArcSDE service can be configured to control the number of application connections as well as the OS resources each connection may obtain. The configuration files – ArcSDE service can be configured to control the number of application connections as well as the OS resources each connection may obtain.

Geographic Features in a SQL Database Feature - abstraction of a real world phenomena A feature attribute - characteristic of a feature“ Thus, a geographic feature is a real world phenomena with a feature attribute that defines its dimension and location in space. In a SQL database, features are managed in tables, an instance of a feature corresponds to a row, and an attribute of a feature to a column.

Data Access Data Access Data access is built around the standard cursor model defined in the Structured Query Language (SQL). The data access model builds on the traditional model by supporting spatial and raster constraints in a query. A database connection is a connection to a source of geographic data. It represents the ArcSDE server, which can respond to requests for geographic information.

Standards for Spatial Data in a SQL database ArcSDE is based on standards for managing spatial data in a SQL database that have been defined by both international standards bodies, and industry organizations: OpenGIS Consortium - Simple Features Specification for SQL ISO , Geographic Information - Simple feature access - Part 1: Common architecture ISO , Geographic Information - Simple feature access - Part 2: SQL option ISO 19107, Geographic information ; Spatial schema ISO , Information technology — Database languages — SQL Multimedia and Application Packages — Part 3: Spatial

SQL and Access SQL – SEQUEL (Structured English Query Language) and was originally an IBM product. Access – readily available to windows user, also provides a good platform on which to learn SQL. Second only to Oracle, Access is the most widely used SQL product in business and industry.

Getting into SQL in Access Path: Queries -> Create query in Design view -> New -> New Query -> Design View -> Close Show Table -> Click “SQL” button Typing a simple SQL query: Select * From Student Where class=4

Running s SQL Query You can save your query when you try to close your query window, or through File/Save menu Click to run the script

Editing a SQL Query

Viewing Table Design

Beginning SQL Commands in Access Basic statements in SQL – The Select Statement Selecting Fields Using Order BY Using ASC or DESC Ordering Within an Order Selecting Rows (Tuples) The Where Clause Using AND Using OR

Beginning Statements SQL statements in Access must begin with one of the following commands: Select Select Insert Insert Delete Delete Update Update Procedure Procedure Select is the most commonly used command

The SELECT Statement Select Syntax: SELECT fields FROM Tables; As in most versions of SQL, SQL commands in Access have to be terminated by semicolon. The “*” means “all fields” of the table: Select * FROM Student;

Selecting Fields Select one field: SELECT field_name FROM table; SELECT sname FROM Student; Select More than one field: Select sname, class FROM Student; Using ORDER BY: SELECT sname, class FROM Student ORDER BY class;

Using ASC or DESC SELECT sname, class FROM Student ORDER BY class ASC; Ordering Within an Order: SELECT sname, class FROM Student ORDER BY class DESC, sname;

SELECTING Rows (Tuples) The WHERE Clause can restrict the output of rows in the results set by adding a WHERE clause. SELECT fields or attributes or columns FROM Table WHERE criteria; SELECT * FROM Student WHERE class=4;

Comparisons Operators All that can be used in a WHERE clause are listed here: > <> <> = >= >= <= <=

Logical Operators To include multiple conditions in a WHERE clause, logical operators, AND and OR, and the BETWEEN operator may be used. Using AND Using AND SELECT * FROM Student WHERE class = 5 AND major = ‘ACCT’;

Using OR and BETWEEN SELECT * FROM Student WHERE class = 4 OR major = ‘ACCT’; SELECT … FROMWHERE BETWEEN value1 and value2 Question – could you write a SQL scripts to find all students of class 1, 2, and 3?

The COUNT Function Number of rows what will be obtained in a result set without actually displaying all of the result set itself. SELECT COUNT(*) FROM Student; SELECT COUNT(class) FROM Student; Question – did you get same output from above examples? Why?

NULL Values NULL values are used to designate missing data in tables. SELECT sname, class FROM Student WHERE class IS NULL;

Using Aliases We can enhance the output and readability of a query by using column and table aliases. SELECT sname AS Student_name, major AS Student_major, class AS Student_class FROM Student Where class = 4; A Table alias is a temporary name for a table that allows us to short-hand a table’s name when we reference that table in a query. SELECT s.sname FROM Student s WHERE s.class = 4

Table Qualifiers SELECT * FROM Student WHERE student.class = 4

A Convention for Writing SQL Statements Use Uppercase letters for keywords Use Uppercase letters for keywords Align the keywords on separate lines. Align the keywords on separate lines. Access does not allow comments in the SQL window Access does not allow comments in the SQL window Single quotes and double quotes have the same meaning. Single quotes and double quotes have the same meaning. Access allows blank lines in the SQL window, but does not allow any characters after the semicolon. Access allows blank lines in the SQL window, but does not allow any characters after the semicolon.

Creating and Populating Tables Data Types in Access Opening a Database -Creating a New Database to Create a Table -Opening an Existing Database to Create a table Creating a table Inserting Values into a table The Update Command The Alter Table Command

Data Types in Access Access supports 14 primary data types: Text, Char, Integer, Real, Float, Decimal, Smallint, Tinyint, Money, Datetime, Binary, Bit, Image, and UniqueIdentifier.

Internal/External names The synonyms are external names. Valid synonyms for the Text field are: LONGTEXT, LONGCHAR, NOTE, NTEXT, and MEMO. Similar structures exist for other data types.

Opening a Database You can create a new database from scratch, or open an existing one. (Try this by yourself to see how.) To introduce new data into your database, you will need to create tables. CREATE TABLE Tablename (attribute_name type, attribute_name, type, ….); Example: CREATE TABLE Employee (nameVARCHAR(20), addressVARCHAR(20), employee_number NUMBER, salaryCURRENCY);

Inserting Values into a Table Using INSERT INTO … VALUES INSERT INTO Names VALUES(‘Joe Smith’); Note – Names is the name of an existing table INSERT INTO Employee VALUES (‘Joe Smith’, ‘102 Hamilton Av.’, 101, 2500); Note – if an attribute is unknown, you need to use “NULL” to identify Values (‘Joe Smitch’, null, 101, null)

Using INSERT INTO.. SELECT This is useful for inserting multiple rows. INSERT INTO target_table(field) “Select clause”; Example: INSERT INTO Names(name) SELECT name FROM Employee; Question: Can you add employees with salary > 2600?

The Update Command For example set all salaries in the table Emp2 to zero, you may do so with one update command: UPDATE Emp2 SET sal = 0; UPDATE Employee SET salary = 0 WHERE employee_number = 101

The Alter Table Command ALTER TABLE Tablename ADD column-name type; ALTER TABLE Employee ADD balance CURRENCY; Changing a Column’s Type in a table ALTER TABLE EMPLOYEE ALTER COLUMN balance NUMBER;

Deleting a Column in a Table ALTER TABLE Tablename DROP column-name; You can also delete rows from a table: DELETE FROM Table WHERE (condition); DELETE * FROM Employee WHERE salary>100