It 203 Unit 4 Slides

Post on 21-Feb-2015

31 views 0 download

Transcript of It 203 Unit 4 Slides

Unit 6Unit 6

Creating and Using Creating and Using DatabasesDatabases

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

SQL Server Data TypesSQL Server Data Types

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

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

• User-defined data types

• User-defined functions

• Users• Roles

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.

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.

ConstraintsConstraints

Click on “New”

Enter a name for the constraint.

Enter the constraint expression as shown.

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.

Arcade DatabaseArcade Database

MEMBER TableMEMBER Table

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.

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.

LIKE OperatorLIKE Operator

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

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

AND and ORAND and OR

Conditions: jumps > 10 AND skill = ‘I’

Conditions: jumps > 10 OR skill = ‘I’

SELECT with ANDSELECT with AND

AND ResultsAND Results

SELECT with ORSELECT with OR

OR ResultsOR Results

IN OperatorIN Operator

BETWEEN OperatorBETWEEN Operator

NOT OperatorNOT Operator

Aggregate FunctionsAggregate Functions

Sample Data DiagramSample Data Diagram

Sample QuerySample Query

Cartesian ProductCartesian Product

Multiple Filter ConditionsMultiple Filter Conditions

Processing Join QueryProcessing Join Query

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

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

OR Without ParenthesesOR Without Parentheses

OR With ParenthesesOR With Parentheses