Download presentation
Presentation is loading. Please wait.
Published byBrandon York Modified over 8 years ago
1
Visual C# 2012 How to Program ©1992-2014 by Pearson Education, Inc. All Rights Reserved.
5
Database: Organized integrated collection of data Database management system (DBMS) Provides mechanisms for storing and organizing data Allows storage and access to database, without knowledge of internal representation Relational Databases popular Use Structured Query Language (SQL) to perform queries (search) and manipulate data Programming languages need an interface to interact with relational databases
6
6 Logical representation of data: Relationships can be considered without concern for physical structure of data Composed of tables
7
©1992-2014 by Pearson Education, Inc. All Rights Reserved.
8
8 Rule of Entity Integrity: every record must have a unique value in its primary-key field Compound Primary key: when a record has a unique key based on a combination of two fields Foreign key: Field for which every entry has a unique value in another table and where the field in the other table is the primary key for that table Rule of Referential Integrity: every foreign-key field value must appear in another table’s primary-key field One to many relationship: A foreign key can appear many times in its own table, but only once as primary key in another table
9
©1992-2014 by Pearson Education, Inc. All Rights Reserved. New sets made from queries called result sets Result set formed by selecting Department and Location data from the Employee table.
10
©1992-2014 by Pearson Education, Inc. All Rights Reserved.
18
18 Used to request data (perform queries) and manipulate data
19
19
20
20 Extracts information from one or more tables in a database Format: Basic: SELECT * FROM tableName * extracts all columns To get specific fields use a comma separated list instead of * Example: SELECT * FROM Authors
21
21 SELECT * FROM Authors
22
22 Used to specify certain criteria in a query Basic form: SELECT * FROM tableName WHERE criteria Example: SELECT * FROM Titles WHERE copyright > 1999 Can use LIKE clause Used for pattern matching Uses wildcards *: zero or more characters take its place ?: exactly one character takes its place
23
23
24
24
25
25 Used to arrange results of a query Can be ascending or descending order Uses ASC and DESC respectively Example: SELECT * FROM Authors ORDER BY lastName ASC Can be used to sort by multiple fields
26
26
27
27
28
28 INNER JOIN Merges records from multiple tables into a single record Tests for matching values in a common field General Form: SELECT * FROM table1 INNER JOIN table2 ON table1.fieldName=table2.fieldName Fully-qualified names use the table name and dot operator followed by the field name Example: SELECT firstName, isbn FROM Authors INNER JOIN AuthorISBN ON Authors.authorID= AuthorISBN.authorID
29
29
30
30 Tables produced by INNER JOIN can be used as arguments for another INNER JOIN
31
31 TitleAuthor query of Books database. Join Publishers and Titles tables if the publisherID matches Join Authors and AuthorISBN if authorID matches Join two created tables if titlesISBN matches authorsISBN Sort new table by title
32
32 Part 1
33
33 Inserts a new record into a table General Form: INSERT INTO tableName(fieldName1) VALUES (value1) Values must match field names in order and type Example: INSERT INTO Authors (firstName, lastName) VALUES (‘Sue’, ‘Smith’)
34
34
35
35 Modifies data in a table Form: UPDATE tableName SET fieldName1 = value1 WHERE criteria Example : UPDATE Authors SET lastName = ‘Jones’ WHERE lastName = ‘Smith’ AND firstName = ‘Sue’
36
36
37
37 Removes data from a table Form: DELETE FROM tableName WHERE criteria Example: DELETE FROM Authors WHERE lastName = ‘Jones’ AND firstName = ‘Sue’
38
38
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.