Professional Documents
Culture Documents
How To:
Table of Contents
4.0 Conclusion..............................................................................................................................10
1.0 Introduction
Hello, my name is Roshelle Thompson and I am a senior at Florida State University, majoring in Information Technology. Database Administration and Web Development are the two aspects that thrill me the most in the IT field. I enjoy learning new things, and do so with ease. I believe that my superior customer service skills allow me to communicate with the client in order to ensure not just satisfaction, but a general positive relationship between the company and client. I will be showing you how to create an Entity Relationship diagram, a simple database, and populate that database, using MySQL. This manual was written for an audience with basic database knowledge who are familiar with terms such as entity, attribute, foreign key, and primary key. It is also to supplement my How To video found at www.youtube.com/
How To Create and Populate a Basic Database Using MySQL 2009 3.1.1 Department Table
department ID* 1 2 3 dName HR Accountin g Sales managerI D* 2 1 3
managerID* 1 2 3
*Please note that the employeeID, managerID, and departmentID are unique, auto generated numbers.
How To Create and Populate a Basic Database Using MySQL 2009 you will choose the Database Model Diagram (US units) You will then see a table to the left of the screen which contains different shapes that will help you create the diagram. Click on the Entity shape and drag it to your black page.
From here you will see a Database Properties table at the bottom of the screen. In the Definition category, you can change the physical name of the Entity to anything you would like. In our case we will name our first table Department.
3.2.2 Assigning Attributes Next you will want to go into the Columns category to add the attributes. Here you can type in each attributes name into the Physical Name column. You will also want to select the data type for each, either by using the drop down menu or physically inputting it. You are able to make an attribute the Primary Key, or PK, by checking the box towards the right. Microsoft Visio will also automatically make this attribute required. You do not need to worry about adding in the Foreign Keys, as they will be added automatically when relationships are created between entities. When finished your Columns category should look as follows:
Repeat this for each entity you are adding. I have chosen to use the Data Type VARCHAR(15) for every name, and VARCHAR(12) for the phone numbers. The IDs will all be classified as INTEGERS. When finished your entities should look as follows:
3.2.3 Defining Relationships The next step to creating the ER Diagram is to define the relationships. There are three different types of relationships: one-to-many, many-tomany, and one-to-one. Looking at our entities we can deduce that there are three relationships present: ONE Manager to MANY Employees ONE Department to MANY Employees ONE Manager to ONE Department As you can see, we have two one-to-many relationships, and one one-toone. To show these relationships in your ER Diagram you must first select the Relationship shape, located to the left of the screen, as well as the connector tool located at the top.
Once you have selected these options, you are ready to draw the relationship. To do this you must first point your curser over the entity on the One side of the relationship, in this case the Database entity, until its border becomes red. From here, guide your mouse over to the entity on the Many side, which will be the Employee entity for us. Once that entitys border turns red, release the mouse and an arrow will appear. Microsoft Visio will automatically add the PK of the Many entity as an FK in the One entity. If the relationship is one-to-one, it does not matter which PK becomes the FK, I chose to make managerID the FK in Department. Repeat this for any and all relationships in the diagram. In the end, your diagram should look as follows:
* Please note: anything in the square brackets is to be filled in with your own information ** This line tells MySQL to automatically assign a number for this field, incrementing by one each time. This ensures that the primary key is in fact unique. For this demonstration, my CREATE statement for the Department entity would be:
CREATE TABLE Department ( departmentID auto_increment, dName varchar(15), managerID int ) ; int primary key
How To Create and Populate a Basic Database Using MySQL 2009 3.3.2.2 The INSERT INTO Statement To add actual data into the table we must use the INSERT INTO statement. The syntax for this is as follows:
INSERT INTO [entity name] VALUES (NULL, [varchar or char], [int] );
For data that is automatically entered, such as the primary key in our place, the value would be NULL. If entering a varchar or char data type it must be enclosed in single quotations. Integers do not need any quotations, you can simply write them in. Each piece of data must be separated by a comma, and there must also be a semi-colon at the end. You must construct a INSERT statement for each row of data in your entity. For the demonstration, my INSERT INTO statements for the Department entity would be:
INSERT INTO Department VALUES (NULL, HR, 2); INSERT INTO Department VALUES (NULL, Accounting, 1); INSERT INTO Department VALUES (NULL, Sales, 3);
4.0 Conclusion
By following each of my steps you will be left with a fully functional database. I have shown you how to construct a Entity Relationship Diagram, and actually Create and add data to a database. From here I encourage you to learn more about databases such as how to query specific information, or how to add users with passwords. The MySQL website, www.mysql.com, has many reference manuals that do a great job in assisting you on your SQL journey. Any comments, questions, roshellethompson@gmail.com or concerns can be sent to my email: