Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I need help with this lab to complete assignment. This requires MySQL Workbench. I did step 1 , need help with remaining steps. Next, we
I need help with this lab to complete assignment. This requires MySQL Workbench. I did step need help with remaining steps.
Next, we will create a table in order to help us keep track of photographs. As you know, today's digital cameras can record not only a picture but the GPS location of the picture. We wish to keep this information and eventually display it on a map so we can see where our pictures are located.
We begin by naming some of the data we will keep within our database. For example we would like to keep the name and address of the user of the database, along with their password to access the database. We would also like to keep the city, state, zip code, and telephone number of the person using the database.
From the 'finalproject' schema, create a new table and label it users. The following fields should be created:
userid
name
username
address
city
state
zip
password
We must also think about the data types of each of these attributes in the users table. We can make the data types to be:
userid numeric, integer, not null, primary key, unique, autoincrement
name alphanumeric
username alphanumeric characters
address alphanumeric
city alphanumeric
state alphanumeric characters
zip numeric integer digits
password alphanumeric
The second table we will need is the one to hold the locations for people and locations where the photos were taken. This table will be called locations. It needs to contain two items for identification and another two items for the actual location.
itemid numeric, integer, not null, autoincrement
type numeric, integer
description alphanumeric
lng real
lat, real
In the LOCATIONS table itemid contains either a userid or a photograph id depending what location it represents. The type refers to whether the location entry refers to a person or a photograph. The description is an alphanumeric textual field that describes the person or the photograph location. Lastly, lng contains the longitude of the location and lat contains the latitude of the location.
The remaining table is the photograph table. This table contain two fields, one for the photograph an id and the second to the location of the photograph. Name this table photographs.
photoid numeric, integer
locationid numeric integer
For the photograph table, use SQL to create the table. In MySQL Workbench, click the icon labeled SQL with the plus sign:
In the workbench window, type the correct CREATE TABLE statement to add the photoid and the locationid fields, ensuring the proper type is used.
For each table created, be sure to capture a screen print.
Prompt Alter Tables
We wish to make some changes to each of the tables. When a row is created in any of the tables we do not want to allow NULL values.
In order to make a change to a table, the ALTER statement is used. Below is an example of how to modify the users table to ensure the userid is not null:
ALTER TABLE users MODIFY userid INT NOT NULL;
This will change the field userid in the table users so that this field cannot have NULL values.
Create a new SQL statement and modify the following fields so that they are not null.
Table Fields
locations type, description, lng lat
users name, username, password
photograph photoid, locationid
Paste the SQL statements in the Word document with a heading of Prompt Alter Tables.
Prompt Create Index
Next we want to make userid an index for the users table. An index is usually created when a table is created but we can also create the index separately using the CREATE INDEX statement.
CREATE UNIQUE INDEX id ON users userid;
This statement create an index called id where each KEY will be unique different from any other The table users will be used and the index will be based on the first named userid.
Now that the index is created on the users table, add an index for the photograph table.
Execute these commands in a new SQL creation window. After running the command, rightclick on the photograph table in the Schema panel and click Table Inspector. Click the indexes tab and take a screen print. Paste the SQL statements and screen capture under Prompt
Prompt Enter Data
Now let's enter some data into the database.
We will enter data for the following four individuals.
Userid name username address city state zip password
Bonnie Buntcake bbunt Wonder Street Wonderbread OH eclectic
Sam Smarf ssmarf A Street Beefy PA swimming
Wendy Grog wgrog Star Street Mary MD wells
Joe Jogger jjogger N North Street Norther WV tarts
To enter data into a table you can use the INSERT statement.
INSERT INTO tablename column column
INSERT INTO users VALUES Bonnie Buntcake', 'bbunt', Wonder Street', 'Wonderbread', OH 'eclectic';
We don't enter the userid because we set it to an autonu
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started