Running Head: DATABASE MANAGEMENT REPORT 1 7-1 Final Project Database Management Report Deborah Hook Southern New Hampshire University June 30, 2019 DATABASE MANAGEMENT REPORT 2 Database Management Report Task one INSERT INTO is used for inserting data into a specific table and person was the specific table to be used. The specific columns to be used were first_name and last_name so those were put into the () and the next section of the statement was the VALUES statement which is used to fill the columns with the specific values that you want in those columns and in this case it was my name and so those must have "" around the words. DATABASE MANAGEMENT REPORT 3 Task 2 One of the functions of ALTER TABLE is to add to the table and this task was to ADD a column so to do that the table name must be listed after the initial statement and this was going to be in the person table. The name of the column to be added is age. After that there are several attributes that could be added to define the column, this one will have INT which is for numbers between -2147483648 to 2147483647 normally and must have the number of digits assigned to it within the () and for this column I chose 3 because an age could reach 100. For this number to not be in the negative it must be UNSIGNED. It was NOT NULL which means that information must be provided in the column. DATABASE MANAGEMENT REPORT 4 Task 3 UPDATE lets us update the records from an existing database table and this time I am updating the table person. I am going to change some of the data in the age column, the ones where the person_id column equals 7, to the value 52 and to do this I use the SET statement and choose the age column use the = sign and use 52. Then use the WHERE statement and the person_id column and the = and the number 7. DATABASE MANAGEMENT REPORT 5 Task 4 DELETE lets us delete the records from an existing database table. This time I use the FROM statement and then use the table person. Then I use the WHERE statement to indicate which column and which value I want to delete by using the equal sign, so I use the first_name column = 'Diana' and then I use the AND to indicate there is another and I pick the next column last_name = 'Taurasi' DATABASE MANAGEMENT REPORT 6 Task 5 One of the functions of ALTER TABLE is to add to the table and this task was to ADD a column so to do that the table name must be listed after the initial statement and this was going to be in the contact_list table. The name of the column was favorite. After that there are several attributes that could be added to define the column, this one was to have VARCHAR which is variable character field and can have letters, characters, and characters, it needs to have the amount of characters defined up to 255 with the () around that number and for this column it was 10 and it was NOT NULL which means that information must be provided in the column. DATABASE MANAGEMENT REPORT 7 Task 6 UPDATE lets us update the records from an existing database table and this time I am updating the table contact_list. I am going to change some of the data in the favorite column, the ones where the contact_id column equals 1, to the value y and to do this I use the SET statement and choose the favorite column use the = sign and use y surrounded with ''. Then use the WHERE statement and the contact_id column and the = and the number 1. DATABASE MANAGEMENT REPORT 8 Task 7 UPDATE lets us update the records from an existing database table and this time I am updating the table contact_list. I am going to change some of the data in the favorite column, the ones where the contact_id column doesn't equal 1, to the value n and to do this I use the SET statement and choose the favorite column use the = sign and use n surrounded with ''. Then use the WHERE statement and the contact_id column and the <>, which means not equal to, and the number 1. DATABASE MANAGEMENT REPORT 9 Task 8 INSERT INTO is used for inserting data into a specific table and contact_list was the specific table to be used. The specific columns in the table were connection_id, person_id, contact_id, and favorite, but the first column connection_id does not need to be listed in INSERT INTO statement because it is automatically generated with numbers in sequential order starting at 1. So, the column names used are person_id, contact_id, and favorite so those were put into DATABASE MANAGEMENT REPORT 10 the (). The next section of the statement is the VALUES statement which is used to fill the columns with the specific values that you want in those columns and in this case, I was to add 3 new records. The numbers do not need "" or '' but the characters need ''. Task 9 CREATE is part of defining where and how data is stored and one way is in creating tables. This statement can also be used to create other things like databases, but in this case I am creating a TABLE called image and then an ( and a new line and then start defining what columns are needed in this table and what kinds of columns. For this table the first column is an id column called image_id and it will be an INT type of column with a value of 8 digits and it is UNSIGNED so it will be a positive number and it is NOT NULL so it is required and it is auto_increment which means that whenever a row is created, increment the value of the id column automatically. The next column is named image_name and the type is VARCHAR and has 50 allowed and is NOT NULL which again means it is required. The third column is named DATABASE MANAGEMENT REPORT 11 image_location and is the type VARCHAR and is allowed 250 characters and is also NOT NULL or a required column. The next statement is the PRIMARY KEY, is a column in a table which must contain a unique value which can be used to identify each row of a table uniquely. These columns are put into (). For this table the primary key is image_id. Task 10 By using CREATE a new table can be created to pull information from 2 different tables into 1 table. To create the new table name the TABLE message_image and then an (. Then a new line and start defining what columns are needed in this table. For this table the first column is an id column named message_id and it will be an INT type of column with a value of 8 digits and it is NOT NULL so it is required. The next column is also an id column named image_id and it will be an INT type of column with a value of 8 digits and it is NOT NULL so it is required. The next statement is the PRIMARY KEY, is a column in a table which must contain a unique DATABASE MANAGEMENT REPORT 12 value which can be used to identify each row of a table uniquely. These columns are put into (). For this table the primary keys are message_id and image_id. Task 11 INSERT INTO is used for inserting data into a specific table and image was the specific table to be used. The column names used are image_name, and image_location they are put into the (). The next section of the statement is the VALUES statement which is used to fill the columns with the specific values that you want in those columns and in this case, I was to add 5 new records. Each new record needed to be surrounded with "". DATABASE MANAGEMENT REPORT 13 Task 12 INSERT INTO is used for inserting data into a specific table and message_image was the specific table to be used. The column names used are message_id and image_id they are put into the (). The next section of the statement is the VALUES statement which is used to fill the columns with the specific values that you want in those columns and in this case, I was to add 5 new records. Since each new record was a number they did not need "" or ''. DATABASE MANAGEMENT REPORT 14 Task 13 This task was to find specific data from different tables so I used the SELECT statement which manipulates the data and can be used to select data from different columns from different tables. I also want to name the columns specific titles when I display them, so I use the AS statement which is the alias statement which is used for clarity and efficiency. So, after the AS statement I put the new name in "". Then I used the FROM statement to obtain where the data is being taken from. The next line I use the WHERE clause, it allows us to use conditional operators in order to be more precise with our data. In the WHERE clause I select records that have a valid FOREIGN KEY that match each other in column values so m.sender_id = s.person_id AND m.receiver_id = r.person_id. Then specific to this task I was to find the messages that Michael Phelps sent so I added specific WHERE clauses that included to look for his first name and his last name: s.first_name = 'Michael' AND s.last_name = 'Phelps'. DATABASE MANAGEMENT REPORT 15 Task 14 This task was to find the number of messages sent for every person so I used the SELECT statement which manipulates the data and can be used to select data from different columns from different tables. COUNT (*) was added in this statement to count all the messages. The (*) tells the statement to include all. I also want to name the columns specific titles when I display them, so I use the AS statement which is the alias statement which is used for clarity and efficiency. So, after the AS statement I put the new name in "". Then I used the FROM statement to obtain where the data is being taken from. The next line I use the WHERE clause, it allows us to use conditional operators in order to be more precise with our data. In the WHERE clause I select records that have a valid FOREIGN KEY that match each other in column values so m.sender_id = p.person_id. Then I used the GROUP BY statement which is used to group the result-set by one or more columns. This result was grouped by p.person_id, p.first_name, and p.last_name. DATABASE MANAGEMENT REPORT 16 Task 15 This task was to find all the messages that have at least one image attached to it so again I used the SELECT statement which manipulates the data and can be used to select data from different columns from different tables. I also want to name the columns specific titles when I display them, so I use the AS statement which is the alias statement which is used for clarity and efficiency. So, after the AS statement I put the new name in "". Then I used the FROM statement to obtain where the data is being taken from. Then I used the INNER JOIN query. This joins two tables together. Now we can match values of the two tables columns together that have valid FOREIGN KEYS. I used two INNER JOIN queries for this task to accomplish the goal of finding all the messages. Then I used the GROUP BY statement which is used to group the result-set by one or more columns.
Enter the password to open this PDF file:
-
-
-
-
-
-
-
-
-
-
-
-