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

Step 1

The document creates a database called my_contacts2 and defines several tables to store contact information, including tables for profession, zip code, status, interests, and information being sought. It then populates these tables with sample data and creates records in the main contacts table linking to this additional information.

Uploaded by

Daba Dashiev
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)
37 views

Step 1

The document creates a database called my_contacts2 and defines several tables to store contact information, including tables for profession, zip code, status, interests, and information being sought. It then populates these tables with sample data and creates records in the main contacts table linking to this additional information.

Uploaded by

Daba Dashiev
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/ 7

Step 1

CREATE DATABASE my_contacts2;

USE my_contacts2;

CREATE TABLE profession(

prof_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,

profession VARCHAR(50) NOT NULL

);

CREATE TABLE zip_code(

zip_code INT NOT NULL AUTO_INCREMENT PRIMARY KEY,

city VARCHAR(50) NOT NULL,

state VARCHAR(50) NOT NULL

);

CREATE TABLE status(

status_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,

status VARCHAR(20) NOT NULL

);

CREATE TABLE interests(

interest_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,

interest VARCHAR(100) NOT NULL

);

CREATE TABLE seeking(

seeking_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,

seeking VARCHAR(100) NOT NULL

);
CREATE TABLE `my_contacts` (

contact_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,

`last_name` varchar(30) ,

`first_name` varchar(20) ,

`email` varchar(50) ,

`gender` char(1),

`birthday` date,

prof_id INT NOT NULL,

zip_code INT NOT NULL,

status_id INT NOT NULL,

CONSTRAINT profession_prof_id_fk

FOREIGN KEY (prof_id)

REFERENCES profession (prof_id),

CONSTRAINT zip_code_zip_code_fk

FOREIGN KEY (zip_code)

REFERENCES zip_code (zip_code),

CONSTRAINT status_status_id_fk

FOREIGN KEY (status_id)

REFERENCES status (status_id)

);

CREATE TABLE contact_interest(

contact_id INT NOT NULL,

interest_id INT NOT NULL,

CONSTRAINT my_contacts_contact_id_fk
FOREIGN KEY (contact_id)

REFERENCES my_contacts (contact_id),

CONSTRAINT interests_interest_id_fk

FOREIGN KEY (interest_id)

REFERENCES interests (interest_id)

);

CREATE TABLE contact_seeking(

contact_id INT NOT NULL,

seeking_id INT NOT NULL,

PRIMARY KEY (contact_id,seeking_id),

CONSTRAINT my_contacts_contact_id_fk

FOREIGN KEY (contact_id)

REFERENCES my_contacts (contact_id),

CONSTRAINT seeking_seeking_id_fk

FOREIGN KEY (seeking_id)

REFERENCES seeking (seeking_id)

);
Step 2
INSERT INTO profession (profession) VALUES ('Technical Writer'),('Manager'),('Cruise Ship Captain'),
('Software Sales'),('System Administrator'),('Bookshop Owner'),('Unemployed'),('UNIX Sysadmin'),
('Computer Programmer'),('Salesman');

INSERT INTO zip_code (city,state) VALUES ('Palo Alto', 'CA'),('San Francisco', 'CA'),('San Diego', 'CA'),
('Dallas', 'TX'),('Princeton', 'NJ'),('Mountain View', 'CA'),('San Francisco', 'CA'),('San Francisco', 'CA'),('New
York City', 'NY'),('Woodstock','NY');

INSERT INTO status (status) VALUES ('single'),('married'),('single'),('single'),('married'),('single'),


('married'),('married'),('single'),('married');

INSERT INTO interests (interest) VALUES ('relationship'),('women'),('drinking'),('sleeping'),('TV'),


('programming'),('children'),('guitar'),('sleeping'),('football');

INSERT INTO seeking (seeking) VALUES ('friends'),('job'),('nothing'),('friends'),('nothing'),('nothing'),


('love'),('friends'),('pillow'),('job');

INSERT INTO `my_contacts`


(`last_name`,`first_name`,`email`,`gender`,`birthday`,prof_id,zip_code,status_id) VALUES
('Anderson','Jillian','jill_anderson@ \nbreakneckpizza.com','F','1980-09-05','1','1','1');

INSERT INTO `my_contacts`


(`last_name`,`first_name`,`email`,`gender`,`birthday`,prof_id,zip_code,status_id) VALUES
('Kenton','Leo','[email protected]','M','1974-01-10','1','1','1');

INSERT INTO `my_contacts`


(`last_name`,`first_name`,`email`,`gender`,`birthday`,prof_id,zip_code,status_id) VALUES
('McGavin','Darrin',' [email protected]','M','1966-01-23','1','1','1');

INSERT INTO `my_contacts`


(`last_name`,`first_name`,`email`,`gender`,`birthday`,prof_id,zip_code,status_id) VALUES
('Franklin','Joe','[email protected]','M','1977-04-28','1','1','1');

INSERT INTO `my_contacts`


(`last_name`,`first_name`,`email`,`gender`,`birthday`,prof_id,zip_code,status_id) VALUES
('Hamilton','Jamie','[email protected]','F','1964-09-10','1','1','1');

INSERT INTO `my_contacts`


(`last_name`,`first_name`,`email`,`gender`,`birthday`,prof_id,zip_code,status_id) VALUES
('Chevrolet','Maurice','[email protected]','M','1962-07-01','1','1','1');

INSERT INTO `my_contacts`


(`last_name`,`first_name`,`email`,`gender`,`birthday`,prof_id,zip_code,status_id) VALUES
('Kroger','Renee','[email protected]','F','1976-12-03','1','1','1');
INSERT INTO `my_contacts`
(`last_name`,`first_name`,`email`,`gender`,`birthday`,prof_id,zip_code,status_id) VALUES
('Mendoza','Angelina','[email protected]','F','1979-08-19','1','1','1');

INSERT INTO `my_contacts`


(`last_name`,`first_name`,`email`,`gender`,`birthday`,prof_id,zip_code,status_id) VALUES
('Murphy','Donald','[email protected]','M','1967-01-23','1','1','1');

INSERT INTO `my_contacts`


(`last_name`,`first_name`,`email`,`gender`,`birthday`,prof_id,zip_code,status_id) VALUES
('Spatner','John','[email protected]','M','1963-04-18','1','1','1');

SELECT * FROM `my_contacts`;

You might also like