It 203 Unit 4 Slides

33
Unit 6 Unit 6 Creating and Using Creating and Using Databases Databases

Transcript of It 203 Unit 4 Slides

Page 1: It 203 Unit 4 Slides

Unit 6Unit 6

Creating and Using Creating and Using DatabasesDatabases

Page 2: It 203 Unit 4 Slides

Key ConceptsKey Concepts• Creating a database.• Creating user data tables.• Creating relationships.• SELECT statements.• LIKE operator.• IN and BETWEEN operators• AND, OR, and NOT operators• Aggregate functions• Joining tables

Page 3: It 203 Unit 4 Slides

SQL Server Data TypesSQL Server Data Types

Page 4: It 203 Unit 4 Slides

SQL ServerSQL ServerData Types (cont'd)Data Types (cont'd)

Page 5: It 203 Unit 4 Slides

Database ComponentsDatabase Components• Tables• Views• Diagrams• Stored procedures• Rules• Defaults

• User-defined data types

• User-defined functions

• Users• Roles

Page 6: It 203 Unit 4 Slides

New Table Design WindowNew Table Design WindowExpand the database in the Tree pane. Once it is created, right-click on the Tables component (see below) and select “New Table”. The screen to the right will then appear.

Page 7: It 203 Unit 4 Slides

Table ColumnsTable Columns

To create columns, enter a column name, select a Data Type from the drop down list, enter a length and check the Allow Nulls column.

Page 8: It 203 Unit 4 Slides

ConstraintsConstraints

Click on “New”

Enter a name for the constraint.

Enter the constraint expression as shown.

Page 9: It 203 Unit 4 Slides

Primary KeyPrimary Key

Right-click on the email column in the database diagram. Use the Set Primary Key option to specify email as the primary key.

Page 10: It 203 Unit 4 Slides

Arcade DatabaseArcade Database

Page 11: It 203 Unit 4 Slides

MEMBER TableMEMBER Table

Page 12: It 203 Unit 4 Slides

VISIT TableVISIT Table

After this table is created, right-click the member$email column. Then select the Relationships option to create the relationship between the tblVisit and tblMember tables.

Page 13: It 203 Unit 4 Slides

Table PropertiesTable Properties

Click the New button.

Enter a name for the relationship.

The member$email column in the tblVisit table should be matched with the email column in the tblMember table.

Page 14: It 203 Unit 4 Slides

LIKE OperatorLIKE Operator

“%” is a wildcard indicating that any characters can follow the “555”.

Page 15: It 203 Unit 4 Slides

LIKE Operator (cont'd)LIKE Operator (cont'd)

Page 16: It 203 Unit 4 Slides

AND and ORAND and OR

Conditions: jumps > 10 AND skill = ‘I’

Conditions: jumps > 10 OR skill = ‘I’

Page 17: It 203 Unit 4 Slides

SELECT with ANDSELECT with AND

Page 18: It 203 Unit 4 Slides

AND ResultsAND Results

Page 19: It 203 Unit 4 Slides

SELECT with ORSELECT with OR

Page 20: It 203 Unit 4 Slides

OR ResultsOR Results

Page 21: It 203 Unit 4 Slides

IN OperatorIN Operator

Page 22: It 203 Unit 4 Slides

BETWEEN OperatorBETWEEN Operator

Page 23: It 203 Unit 4 Slides

NOT OperatorNOT Operator

Page 24: It 203 Unit 4 Slides

Aggregate FunctionsAggregate Functions

Page 25: It 203 Unit 4 Slides

Sample Data DiagramSample Data Diagram

Page 26: It 203 Unit 4 Slides

Sample QuerySample Query

Page 27: It 203 Unit 4 Slides

Cartesian ProductCartesian Product

Page 28: It 203 Unit 4 Slides

Multiple Filter ConditionsMultiple Filter Conditions

Page 29: It 203 Unit 4 Slides

Processing Join QueryProcessing Join Query

Page 30: It 203 Unit 4 Slides

Processing Join Query Processing Join Query (cont'd)(cont'd)

Page 31: It 203 Unit 4 Slides

Processing Join Query Processing Join Query (cont'd)(cont'd)

Page 32: It 203 Unit 4 Slides

OR Without ParenthesesOR Without Parentheses

Page 33: It 203 Unit 4 Slides

OR With ParenthesesOR With Parentheses