Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Lecture 7 – Database and SQL Database? A database is a collection of associated or related data. Examples – LIS (landuse information databse); Medical."— Presentation transcript:

1 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?

2 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

3 The relational Model Dr. Edgar F. Codd introduced the relational model around 1970. 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”

4 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

5 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.

6

7 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.

8 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.

9 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.

10 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.

11

12 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 ISO19125-1, Geographic Information - Simple feature access - Part 1: Common architecture ISO19125-2, Geographic Information - Simple feature access - Part 2: SQL option ISO 19107, Geographic information ; Spatial schema ISO 13249-3, Information technology — Database languages — SQL Multimedia and Application Packages — Part 3: Spatial

13 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.

14 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

15 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

16 Editing a SQL Query

17 Viewing Table Design

18 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

19 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

20 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;

21 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;

22 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;

23 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;

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

25 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’;

26 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?

27 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?

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

29 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

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

31 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.

32 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

33 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.

34 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.

35 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);

36 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)

37 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?

38 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

39 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;

40 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


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

Similar presentations


Ads by Google