Presentation is loading. Please wait.

Presentation is loading. Please wait.

Working with Derby. RHS – 2009 2 Creating tables We know how to create a database in Derby – an empty database Next step is to add tables to the database.

Similar presentations


Presentation on theme: "Working with Derby. RHS – 2009 2 Creating tables We know how to create a database in Derby – an empty database Next step is to add tables to the database."— Presentation transcript:

1 Working with Derby

2 RHS – 2009 2 Creating tables We know how to create a database in Derby – an empty database Next step is to add tables to the database After adding tables, we can enter data into the tables Remember; design your tables BEFORE using Derby to enter them

3 RHS – 2009 3 Creating tables Before using a database, we must connect to it Right-click on database, and choose ”Connect”

4 RHS – 2009 4 Creating tables Enter whatever we chose when crea- ting the database (hopefully just blanks…)

5 RHS – 2009 5 Creating tables Now we can access the tables in the database – but there are none yet

6 RHS – 2009 6 Creating tables Right-click on ”Tables”, and choose ”Create table”

7 RHS – 2009 7 Creating tables

8 RHS – 2009 8 Creating tables Recall what we need in order to define a table –A proper name for the table –A set of field definitions – a name and a type for each field –A key field – one or more fields the combination of which is always unique

9 RHS – 2009 9 Creating tables Enter a proper name for the table

10 RHS – 2009 10 Creating tables For each data field (also called column), we must add quite a lot of information: –Column name: Name of the data field –Key: Is the field part of the key field –Index: Leave as-is… –Null: Can we omit the value –Unique: Must the value be unique –Data type: Proper type of data –Size: How large can the data be

11 RHS – 2009 11 Creating tables Example: a Name field –Column name: Name –Key: Yes –Null: No –Unique: (decided by choosing ”Key”) –Data type: VARCHAR (means ”String”) –Size: 50 (how long can a name be…?)

12 RHS – 2009 12 Creating tables Example: a Phone field –Column name: Phone –Key: Yes –Null: No –Unique: (decided by choosing ”Key”) –Data type: NUMERIC (number) –Size: 8 (a Danish phone number)

13 RHS – 2009 13 Creating tables

14 RHS – 2009 14 Creating tables A database called Phone Book A table called Friend Two data fields: Name, Phone Red indicates that field is part of key field

15 RHS – 2009 15 Creating tables We can add more data fields later Right-click on the table, choose ”Add Column…”

16 RHS – 2009 16 Creating tables Same as before, but different dialog…

17 RHS – 2009 17 Creating tables Exercise –Create a database called WebShop in Derby –Create three tables in WebShop, called Item, Customer, Sale –Definitions of the tables are given below (key fields are in red) Item ItemNumber ItemName Price Weight NumberInStock IsFragile Description Customer CustomerNumber Name Address ZipCode E-mail ClubMember LastSale Sale CustomerNumber ItemNumber Date NumberOfItems TotalAmount SentToCustomer PaymentReceived

18 RHS – 2009 18 Adding data With the table defini- tion in place, we can now begin to add data to the table Right-click on the table, choose ”View Data…”

19 RHS – 2009 19 Adding data Data in the table is shown here (none yet….)

20 RHS – 2009 20 Adding data Press this icon to add new data

21 RHS – 2009 21 Adding data Type in data for this particular record

22 RHS – 2009 22 Adding data

23 RHS – 2009 23 Adding data Table now con- tains one record

24 RHS – 2009 24 Adding data And so on, and so on…

25 RHS – 2009 25 Adding data What can go wrong…? We might try to type in some data, that does not match the type specification for a particular field Derby will complain…

26 RHS – 2009 26 Adding data What is wrong here…?

27 RHS – 2009 27 Adding data

28 RHS – 2009 28 Adding data The error messages can be more or less easy to understand… It is almost always a matter of trying to enter data of the wrong type Might also be data of incorrect size Some errors are more subtle, like a wrong date (30-02-1988)

29 RHS – 2009 29 Adding data What is this…? An SQL query!

30 RHS – 2009 30 Adding data Exercise –Add a few records to the tables created in the earlier exercise. Try to experiment with the data, such that you also try to add some data with errors. Observe the errors messages that Derby returns when data has errors –Do you now feel comfortable working with Derby, with regards to creating databases, tables and fields, and entering data into tables? If not, then try to invent some more tables, enter them into a database, and enter some data into the tables


Download ppt "Working with Derby. RHS – 2009 2 Creating tables We know how to create a database in Derby – an empty database Next step is to add tables to the database."

Similar presentations


Ads by Google