0% found this document useful (0 votes)
83 views

Modified

The document contains the SQL commands to: 1. Create three tables (users, location, photograph) to store user, location, and photo data with various columns and constraints 2. Alter the tables to modify column properties and add NOT NULL constraints 3. Create an index on the photograph table 4. Insert data into the users and location tables 5. Add a user ID column to the photograph table and modify it to NOT NULL 6. Insert data into the photograph table to link photos to users and locations

Uploaded by

sana fiaz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
83 views

Modified

The document contains the SQL commands to: 1. Create three tables (users, location, photograph) to store user, location, and photo data with various columns and constraints 2. Alter the tables to modify column properties and add NOT NULL constraints 3. Create an index on the photograph table 4. Insert data into the users and location tables 5. Add a user ID column to the photograph table and modify it to NOT NULL 6. Insert data into the photograph table to link photos to users and locations

Uploaded by

sana fiaz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Prompt 1:

Prompt 2:

Users Table:
USE finalproject;
create table users (userid integer not null primary key unique auto_increment,name
varchar(50),username varchar(20),address varchar(50),city varchar(20),state
varchar(2),zip integer(5),password varchar(20));
Location Table:
USE finalproject;
create table location(itemid integer not null primary key auto_increment,type
integer,description varchar(50),lng real, lat real);
Photograph Table:
USE finalproject;
create table photograph(photoid integer,locationid integer);

Prompt 3-Alter Tables:


Users Table:
USE finalproject;
ALTER TABLE users MODIFY userid INT NOT NULL auto_increment;
ALTER TABLE users MODIFY name varchar(50) NOT NULL;
ALTER TABLE users MODIFY username varchar(20) NOT NULL;
ALTER TABLE users MODIFY password varchar(20) NOT NULL;
Location Table:

USE finalproject;
ALTER TABLE location MODIFY type integer NOT NULL;
ALTER TABLE location MODIFY description varchar(50) NOT NULL;
ALTER TABLE location MODIFY lng real NOT NULL;
ALTER TABLE location MODIFY lat real NOT NULL;
Photograph Table:
USE finalproject;
ALTER TABLE photograph MODIFY photoid integer NOT NULL;
ALTER TABLE photograph MODIFY locationid integer NOT NULL;
Prompt 4-Create Index:
USE finalproject;
CREATE UNIQUE INDEX id ON photograph (photoid);

Prompt 5:
INSERT INTO users (name,username,address,city,state,zip,password)
VALUES ( 'Bonnie Buntcake', 'bbunt', '6709 Wonder Street', 'Wonderbread', 'OH',
46105, 'eclectic');
INSERT INTO users (name,username,address,city,state,zip,password)
VALUES ( 'Sam Smarf', 'ssmarf', '356 A Street', 'Beefy', 'PA', 19943, 'swimming');
INSERT INTO users (name,username,address,city,state,zip,password)
VALUES ( 'Wendy Grog', 'wgrog', '900 Star Street', 'Mary', 'MD', 21340, 'wells');
INSERT INTO users (name,username,address,city,state,zip,password)
VALUES ( 'Joe Jogger', 'jjogger', '183713 N North Street', 'Norther', 'WV', 51423,
'tarts');

Prompt 6-Count Rows:


Prompt 7:
alter table photograph Add column userid integer after locationid;
Prompt 8:
We ensure the data integrity by keeping photoid and location id not null.
Now we modify photograph table to ensure data integrity using:
ALTER TABLE photograph MODIFY userid integer NOT NULL;

Prompt 9:
Location Table:
INSERT INTO location (type,description,lng,lat)
values(1,'Independence Hall',794.35,651.43);
INSERT INTO location (type,description,lng,lat)
values( 2, '6709 Wonder Street',323.41,412.22);
INSERT INTO location (type,description,lng,lat)
values( 1, 'Sunrise' ,221.45 ,132.43);
INSERT INTO location (type,description,lng,lat)
values( 2, '356 A Street',123.32,222.43);
INSERT INTO location(type,description,lng,lat)
values( 1, 'Mountains',34.12,87.99);
INSERT INTO location (type,description,lng,lat)
values( 2, '900 Star Street',1071.9,206.45);
INSERT INTO location (type,description,lng,lat)
values( 1, 'Moonrise',816.2,111.2);
INSERT INTO location (type,description,lng,lat)
values( 2, '183714 N North Street',176.11,11.176);

Photograph Table:
INSERT INTO Photograph (photoid,locationid,userid)values(1,2,1),(2,4,1),(3,6,3),
(4,8,4);
Prompt 10:

Prompt 11:
SELECT name FROM users, photograph WHERE users.userid =
photograph.userid;
Prompt 12:
SELECT distinct(name) FROM users, photograph WHERE users.userid =
photograph.userid;

You might also like