Download presentation
Presentation is loading. Please wait.
Published byKatrina Wright Modified over 8 years ago
1
Database Review Terminology Concepts SQL syntax
2
Analysis Terms Term/Concept Definition or Example Relational Model? Relation Instance? Relation Schema? Database Schema? Type Constraint? Data Atomiciy?
3
Analysis Terms Term/Concept Definition or Example Relational ModelUses a n-ary relation between attribute sets to model entity set. Relation InstanceA table with a column for each attribute which is atomic; each row represents an entity. Relation SchemaA relation schema is a relation name (e.g. student, customer, etc.) followed by a parenthesized list of attribute names with associated domains, followed by constraints. Database SchemaCollection of relation schemas. Type ConstraintValue in column must be of corresponding data type Data AtomiciySingle value in each column
4
Analysis Terms Term/Concept Definition or Example Key? Key Constraint? Foreign Key? Constraint ? Candidate Key? Superkey? Functional Dependency ? Determinant?
5
Analysis Terms Term/Concept Definition or Example KeyA set of attributes which uniquely identifies an entity (row) of a relation (table) Key ConstraintAny relation or table has at most one row for some combination of values of key attributes Foreign KeyAn attribute of a relation which serves as a primary key of another relation Foreign Key Constraint There is a tuple or row of the primary key table with same value as value of foreign key (referential integrity Candidate KeyA minimal set of attributes which is a key SuperkeyAny key including set of all attributes of relation Functional Dependency A set of attributes X which uniquely determines a set Y of attributes : X Y DeterminantLeft side of a functional dependency.
6
Analysis Terms Term/Concept Definition or Example Anomaly? Attribute? Binary relation? Cardinality Constraint ? Composite Key? Relational database ?
7
Analysis Terms Term/Concept Definition or Example AnomalyAn error or inconsistency due to redundant data resulting from insertion, update or deletion AttributeA property possessed by every entity in set Binary relationA relation between two entity sets. Cardinality Constraint A bound on the number of times an instance of an entity can be related to an instance of another entity Composite KeyA key consisting of more than one attribute. Relational database A database consisting of relations (tables).
8
Analysis Terms Term/Concept Definition or Example 1st Normal Form? Partial Dependency ? 2nd Normal Form? Transitive Dependency ? 3rd Normal Form? Boyce Codd Normal Form ?
9
Analysis Terms Term/Concept Definition or Example 1st Normal FormEvery attribute is atomic. Partial Dependency A functional dependency in which non-key attributes are functionally dependent on part but not all of the primary key attributes. 2nd Normal FormNo partial dependencies Transitive Dependency A functional dependency between two non-key attributes or attribute sets. 3rd Normal FormNo transitive dependencies, Boyce Codd Normal Form A relation in which every determinant is a candidate key.
10
SQL Syntax Create Table Insert Select Update
11
Basic SQL Syntax Create Table Create ( ) Insert Insert Into ( ) Values( ) Select Select From Where Update Update Set Where
12
SQL Statements SQLSyntax Create Create ( ) ExampleCreate Table Category( Name Text, ID Number, Primary Key(ID)) InsertInsert Into ( ) Values( ) ExampleInsert Into Category (Name,ID) Values("Kitchen",1) SelectSelect From Where ExampleSelect Name From Category UpdateUpdate Set Where ExampleUPDATE Furniture SET Furniture.Price = 20 WHERE Furniture.ID=2 Create Insert Select Update
13
SQL Term/Concept Definition or Example Create TableCreate ( ) Example Statement to create a transaction table as shown below.
14
SQL Term/Concept Definition or Example Create TableCreate ( ) Example Create Table Transaction(XDate date, Amount Currency,Payee Number,Comment text, ID number, Primary Key( ID)) Table
15
SQL Term/Concept Definition or Example SelectSelect From Where * refers to all attributes or columns RentalProperty is table ID = PropertyID Example Embedded SQL in as value of string variable in front end Statement to select a rental property where ID is given ID.
16
SQL Term/Concept Definition or Example SelectSelect From Where * refers to all attributes or columns RentalProperty is table ID = PropertyID Example Embedded SQL in as value of string variable in front end Dim ds As DataSet sql = "Select * from RentalProperty Where ID=" & Id ds = ExecuteSql(sql)
17
SQL – Insert Term/Concept Definition or Example InsertInsert Into ( ) Values ( ) Example Write statement to insert a transaction with the values shown below. Table
18
SQL – Insert Term/Concept Definition or Example InsertInsert Into ( ) Values ( ) Example INSERT INTO [Transaction] Values (#3/1/2009#,100,1,'',1) Table
19
SQL – Update Term/Concept Definition or Example UpdateUpdate Set Example Write an Update statement to change the amount ot the given transaction to 150. Table
20
SQL – Update Term/Concept Definition or Example UpdateUpdate Set Example UPDATE [Transaction] SET [Transaction].Amount = 150; Table
21
SQL – Update Term/Concept Definition or Example Select Example
22
SQL – Select Select Write a Select Query which select recipes from the joins of Category Recipe RecipeCategories – WHERE RecipeCategories.CategoryID = " & catID Example
23
SQL – Select Select Public Function FindRecipesByCategory(ByVal catID As Integer) As List(Of Recipe) Dim sql As String Dim ds As DataSet, dr As DataRow sql = "SELECT Recipe.*" & _ " FROM Category INNER JOIN (Recipe INNER JOIN RecipeCategories ON Recipe.ID = RecipeCategories.RecipeID) ON Category.ID = RecipeCategories.CategoryID " & _ " WHERE RecipeCategories.CategoryID = " & catID ds = ExecuteSql(sql) Dim recipes As New List(Of Recipe) For Each dr In ds.Tables(0).Rows Dim c As New Recipe(dr) recipes.Add(c) Next Return recipes End Function Example
24
SQL – Select Public Function FindIngredientsForRecipe(ByVal rid As Integer) As List(Of Ingredient) Dim sql As String Dim ds As DataSet, dr As DataRow sql = "Select ingredient.* from " & _ " (Recipe INNER JOIN RecipeIngredients ON Recipe.ID = RecipeIngredients.RecipeID) INNER JOIN Ingredient ON RecipeIngredients.IngredientID = Ingredient.ID " & _ " WHERE Recipe.ID = " & rid ds = ExecuteSql(sql) Dim ingredients As New List(Of Ingredient) For Each dr In ds.Tables(0).Rows Dim c As New Ingredient(dr) ingredients.Add(c) Next Return ingredients End Function
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.