Download presentation
Presentation is loading. Please wait.
Published byWhitney Harper Modified over 8 years ago
1
Intro to MySQL 1
2
Open a browser and enter the following address: http://csc-srv1.lasalle.edu:8080/ It should lead to a log in screen. If your name is George Washington, then your username will be c240washingtong If your student id is 1234567, then your password is 1234567was (MySQL usernames can only be 16 characters long. If the above prescription was longer than 16 characters, I stopped at 16. If your name is hyphenated, I only used the first part. ) 2
3
You should have access to 3 items on the left: Northwind, information_schema, and a database that matches your username. 3
4
Looking at a site like brainquote.com, we realize that there is a database behind the scenes. 4
5
Brainyquote entities We see items on the webpage like – Quotes – Authors – Topics 5
6
Choosing a quote reveals more: some of the attributes of the entities as well as some of the relationships between entities. 6
7
Attributes and relationships Attributes: – An author has an occupation, a nationality, a birthdate and death date. Relationships: – A quote is attributed to just one author, but an author may have many quotes attributed to him/her. (Said to be a one-to-many relationship) – A quote might pertain to many topics, and a topic has many quotes that pertain to it. (Said to be a many-to-many relationship) 7
8
Click on the database with your user name and start to create a table for Author data. Choose 7 columns. Click Go. 8
9
Name the fields, choose their type, decode whether of not they can be null. (I also made the id field “auto-increment” A.I.) 9
10
Scroll down and find the Save button. (The Go button is to add another column.) 10
11
Enter some author data and click Go. 11
12
Result of “inserting” author data. 12
13
Click the Browse tab to see the results so far. 13
14
Some decisions I did not insert an ID because I chose the ID field to be “auto-incremented”. An ID should be unique so that it can serve as the primary key – a field which uniquely identifies each row/record in a table. That reminds me I forgot to make the ID into the primary key. 14
15
Click on the Structure tab, check the ID field, and click on the Primary key icon. 15
16
Result of adding the primary key. 16
17
Other decisions The remaining fields were chosen to have the type of varchar with lengths of 30 or 20. 17
18
Could do better It might be better to have a list of nationalities (in another table) and choose the author’s nationality from the list rather than typing it in and risking more typo’s. The same goes for the profession field. 18
19
Dates can be tricky You might have seen in the list of field types a “date type”. This choice would seem to be better for the author’s birth date and death date. But I have seen problems arise with more “historical” dates such as these. The dates supported by the date type don’t go back as far as one might like. 19
20
Now for the quote table/entity We will want – An ID to identify the quote – The text of the quote itself – A quoteAuthorID to establish the relationship between the author and the quote 20 This number is probably the quote’s ID number in brianyquote’s database.
21
Creating the quoteQuote table Create table, name it, add a column if necessary For quoteID choose PRIMARY for Index and AutoIncrement. For quoteAuthorID choose INDEX for Index. (This choice is necessary for establishing the relationship.) Click Go to Add a column Click save to make the table 21
22
After making the quoteQuote table, click on Relationship View 22
23
Use the drop-down list to say that the quoteQuote’s quoteAuthorID will come from the quoteAuthorID field of the quoteAuthor table. Click save. 23
24
With the quoteQuote table selected, click on the Insert tab. Enter the text of the quote. The quoteAuthorID comes from a drop-down which forces it to match one of the authorID’s. 24
25
We just established a “foreign key”. 25
26
Result of the quote insert. 26
27
Browsing the quotes. 27
28
Add at least one more author 28
29
Add at least two more quotes 29
30
Next let us make a quoteTopic table with two fields an ID (primary key and auto-incremented) and a name (varchar 30) 30
31
Next we will make a bridge/junction table to establish the many- to-many relationship between quote and topic. 31
32
Creating the bridge table with two fields – the combination of the two will serve as the primary key. 32
33
Go to Relation view on the “bridge” table. 33
34
Use the drop-down to establish the connection to the other tables. In this bridge table the fields serve as both primary keys and foreign keys. 34
35
Insert a quoteTopic (or two or three) 35
36
Browse the topics 36
37
Insert some relationships between quotes and topics. 37
38
Browse quote topics 38
39
Click on the database (as opposed to a table within the database). Then click on the Designer tab. 39
40
Result of Designer 40
41
What to submit for lab Make a screen capture (by clicking Print Screen or Alt+Print Screen and pasting the result into a Word document) of the structure (the Structure tab) of your tables and the contents of your tables (the Browse tab). Also make a screen capture of the Designer. 41
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.