Sei sulla pagina 1di 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','lkenton@starbuzzcoffee.com','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',' captainlove@headfirsttheater.com','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','joe_franklin@leapinlimos.com','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','dontbother@starbuzzcoffee.com','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','bookman4u@objectville.net','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','poorrenee@mightygumball.net','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','angelina@starbuzzcoffee.com','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','padraic@tikibeanlounge.com','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','jpoet@objectville.net','M','1963-04-18','1','1','1');

SELECT * FROM `my_contacts`;

Potrebbero piacerti anche