Commit a0c48c29 authored by O'Reilly Media, Inc.'s avatar O'Reilly Media, Inc.
Browse files

Initial commit

parents
Loading
Loading
Loading
Loading
+7 −0
Changes for Introduction to MySQL - Working Files/Chapter 1/No Work Files.rtf: 7 added lines, 0 removed lines.
Original line number Diff line number Diff line
{\rtf1\ansi\ansicpg1252\cocoartf1038\cocoasubrtf350
{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
{\colortbl;\red255\green255\blue255;}
\margl1440\margr1440\vieww9000\viewh8400\viewkind0
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural

\f0\fs24 \cf0 No work files for this lesson...}
 No newline at end of file
+287 −0
Changes for Introduction to MySQL - Working Files/Chapter 2/MySQL_Reload_Bookpub.sql: 287 added lines, 0 removed lines.
Original line number Diff line number Diff line
drop table IF EXISTS authors;  
drop table IF EXISTS publishers;
drop table IF EXISTS roysched;
drop table IF EXISTS titleauthors;
drop table IF EXISTS titles;
drop table IF EXISTS sales;
drop table IF EXISTS editors;
drop table IF EXISTS titleditors;
drop table IF EXISTS salesdetails;



DROP TABLE  IF EXISTS author;

DROP TABLE  IF EXISTS book ;

DROP TABLE  IF EXISTS bookauthor; 

DROP TABLE  IF EXISTS bookeditor ;

DROP TABLE  IF EXISTS editor ;

DROP TABLE  IF EXISTS publisher ;






CREATE TABLE author (
  author_id int(11) NOT NULL,
  ssn varchar(11) ,
  lastname varchar(40)  NOT NULL,
  firstname varchar(20)  NOT NULL,
  phone varchar(12) ,
  address varchar(40) ,
  city varchar(20) ,
  state varchar(2) ,
  zip varchar(5) ,
  PRIMARY KEY (author_id)
) ;



CREATE TABLE  book (
  isbn varchar(13)  NOT NULL,
  title varchar(80)  NOT NULL,
  type varchar(12) ,
  pub_id varchar(4) ,
  price decimal(9,2) ,
  advance decimal(9,2) ,
  ytd_sales int(11) ,
  pubdate date ,
  PRIMARY KEY (isbn)
) ;



CREATE TABLE  bookauthor (
  author_id int(11) NOT NULL,
  isbn varchar(13)  NOT NULL,
  author_order int(11) NOT NULL,
  royaltyshare decimal(5,2) ,
  PRIMARY KEY (author_id,isbn)
) ;


CREATE TABLE  bookeditor (
  editor_id int(11) NOT NULL,
  isbn varchar(13)  NOT NULL,
  PRIMARY KEY (editor_id,isbn)
) ;



CREATE TABLE  editor (
  editor_id int(11) NOT NULL,
  ssn varchar(11) ,
  lastname varchar(40)  NOT NULL,
  firstname varchar(20)  NOT NULL,
  phone varchar(12) ,
  editor_position varchar(20)  NOT NULL,
  salary decimal(9,2) NOT NULL,
  PRIMARY KEY (editor_id)
) ;


CREATE TABLE  publisher (
  pub_id int(11) NOT NULL,
  name varchar(40) ,
  address varchar(40) ,
  city varchar(20) ,
  state varchar(2) ,
  PRIMARY KEY (pub_id)
) ;






insert into author
values(998, '998-72-3567', 'Singer', 'Albert',
'801 826-0752', '123 3rd Street', 'St. George', 'UT', '84152')
;
insert into author
values(899, '899-46-2035', 'Singer', 'Anne',
'801 826-0752', '123 3rd Street', 'St. George', 'UT', '84152')
;
insert into author
values(722, '722-51-5454', 'Lance', 'Mike',
'219 547-9982', '3 Bald Eagle Drive', 'Chicago', 'IL', '60631')
;
insert into author
values(807, '807-91-6654', 'Parry', 'Sylvia',
'301 946-8853', '19 Main Street', 'Rockville', 'MD', '20853')
;
insert into author
values(893, '893-72-1158', 'McCluck', 'Serge',
'707 448-4982', '1 Fizzy Street', 'Anaheim', 'CA', '95688')
;
insert into author
values(728, '724-80-9391', 'MacDouglas', 'Spencer',
'415 354-7128', '47 Cumbre Ct.', 'Oakland', 'CA', '94612')
;
insert into author
values(427, '427-17-2319', 'Dingy', 'Ann',
'415 836-7128', '3410 RedWing St.', 'Santa Clara', 'CA', '94301')
;
insert into author
values(672, '672-71-3249', 'Suko', 'Ahi',
'415 935-4228', '3 Silver Ct.', 'Walnut Creek', 'CA', '94595')
;
insert into author
values(267, '267-41-2394', 'Farhey', 'Michael',
'408 286-2428', '44 Homestead Pkwy', 'San Jose', 'CA', '95128')
;
insert into author
values(472, '472-27-2349', 'Dunhill', 'Curt',
'707 938-6445', 'PO Box 792', 'Santa Clara', 'CA', '94301')
;
insert into author
values(527, '527-72-3246', 'Blue', 'Robert',
'615 297-2723', '22 Cowboy Rd.', 'Nashville', 'TN', '37215')
;
insert into author
values(172, '172-32-1176', 'Black', 'John',
'408 496-7223', '10932 Bigge Rd.', 'Menlo Park', 'CA', '94025')
;
insert into author
values(724, '724-08-9931', 'McGyver', 'Dirk',
'415 843-2991', '752 Telescope Rd.', 'Oakland', 'CA', '94609')
;
insert into author
values(274, '274-80-9391', 'Straight', 'Richard',
'415 834-2919', '5420 University Av.', 'Oakland', 'CA', '94609')
;
insert into author
values(756, '756-30-7391', 'Karsen', 'Lynda',
'415 534-9219', '72 James St.', 'Oakland', 'CA', '94609')
;
insert into author
values(712, '712-45-1867', 'Castillo', 'Jose',
'615 996-8275', '28 Park Pl. #86', 'Ann Arbor', 'MI', '48105')
;
insert into author
values(846, '846-92-7186', 'Hunter', 'Cindy',
'415 836-7128', '41 Smart St.', 'Palo Alto', 'CA', '94301')
;
insert into author
values(486, '486-29-1786', 'Lockley', 'Sharon',
'415 585-4620', '18 Brooklyn Av.', 'San Francisco', 'CA', '94130')
;
insert into author
values(648, '648-92-1872', 'Hall', 'Mark',
'503 745-6402', '55 Valley Blvd.', 'Corvallis', 'OR', '97330')
;
insert into author
values(341, '341-22-1782', 'Smith', 'Marge',
'913 843-0462', '10 Misisipi Dr.', 'Lawrence', 'KS', '66044')
;

insert into author
values(409, '409-56-7008', 'Adams', 'Abraham',
'415 658-9932', '622 Robin St.', 'Berkeley', 'CA', '94705')
;
insert into author
values (213, '213-46-8915', 'Blue', 'Maggie',
'415 986-7020', '397 83rd St. #431', 'Oakland', 'CA', '94618')
;
insert into author
values(238, '238-95-7766', 'Carson', 'Honey',
'415 548-7723', '89 MLK Blvd.', 'Berkeley', 'CA', '94705')
;




INSERT INTO book (isbn, title, type, pub_id, price, advance, ytd_sales, pubdate) VALUES('1-8888-8888-x', 'Silicon Valley Start-ups', 'computer', '3', '40.00', '8000.00', 4095, '2012-06-12');
INSERT INTO book (isbn, title, type, pub_id, price, advance, ytd_sales, pubdate) VALUES('1-1032-1032-x', 'One Hour Negotiations', 'business', '3', '29.99', '5000.00', 4095, '2012-06-12');
INSERT INTO book (isbn, title, type, pub_id, price, advance, ytd_sales, pubdate) VALUES('1-3333-3333-x', 'Analyzing the Obsessive', 'psychology', '1', '29.99', '2000.00', 4072, '2012-06-12');
INSERT INTO book (isbn, title, type, pub_id, price, advance, ytd_sales, pubdate) VALUES('1-1111-1111-x', 'Where is my Break-Even Point?', 'business', '3', '21.95', '5000.00', 3876, '2012-06-09');
INSERT INTO book (isbn, title, type, pub_id, price, advance, ytd_sales, pubdate) VALUES('1-2222-2222-x', 'Treats and More Treats', 'cooking', '2', '29.99', '0.00', 2032, '2012-06-09');
INSERT INTO book (isbn, title, type, pub_id, price, advance, ytd_sales, pubdate) VALUES('1-7777-7777-x', 'Gluten Free or Die', 'cooking', '2', '29.99', '8000.00', 4095, '2012-06-12');
INSERT INTO book (isbn, title, type, pub_id, price, advance, ytd_sales, pubdate) VALUES('1-4203-4203-x', 'Twenty Meals you can make in 20 minutes', 'cooking', '2', '21.95', '4000.00', 15096, '2012-06-12');
INSERT INTO book (isbn, title, type, pub_id, price, advance, ytd_sales, pubdate) VALUES('1-1035-1035-x', 'Usability Testing', 'computer', '3', '42.95', '7000.00', 8780, '2012-06-30');
INSERT INTO book (isbn, title, type, pub_id, price, advance, ytd_sales, pubdate) VALUES('1-2075-2075-x', 'Are You Stressed for Success?', 'business', '1', '12.99', '10125.00', 18722, '2012-06-15');
INSERT INTO book (isbn, title, type, pub_id, price, advance, ytd_sales, pubdate) VALUES('1-2091-2091-x', 'Sleep Depreviation and Mood Therapy', 'psychology', '1', '21.95', '2275.00', 2045, '2012-06-15');
INSERT INTO book (isbn, title, type, pub_id, price, advance, ytd_sales, pubdate) VALUES('1-2106-2106-x', 'Instilling Courage', 'psychology', '1', '17.00', '6000.00', 111, '2012-10-05');
INSERT INTO book (isbn, title, type, pub_id, price, advance, ytd_sales, pubdate) VALUES('1-3021-3021-x', 'Fresh and Easy?', 'cooking', '2', '12.99', '15000.00', 22246, '2012-06-18');
INSERT INTO book (isbn, title, type, pub_id, price, advance, ytd_sales, pubdate) VALUES('1-3218-3218-x', 'Stop and Smell the Humus', 'cooking', '2', '40.95', '7000.00', 375, '2012-10-21');
INSERT INTO book (isbn, title, type, pub_id, price, advance, ytd_sales, pubdate) VALUES('1-3026-3026-x', 'The Psychology of Social Networking', NULL, '2', NULL, NULL, NULL, NULL);
INSERT INTO book (isbn, title, type, pub_id, price, advance, ytd_sales, pubdate) VALUES('1-7832-7832-x', 'How to Choose a Computer', 'business', '3', '29.99', '5000.00', 4095, '2012-06-22');
INSERT INTO book (isbn, title, type, pub_id, price, advance, ytd_sales, pubdate) VALUES('1-1372-1372-x', 'Dealing with Behavior Problems in the Workplace', 'psychology', '1', '41.59', '7000.00', 375, '2012-10-21');



INSERT INTO bookauthor (author_id, isbn, author_order, royaltyshare) VALUES(409, '1-1032-1032-x', 1, '0.60');
INSERT INTO bookauthor (author_id, isbn, author_order, royaltyshare) VALUES(486, '1-5555-5555-x', 1, '1.00');
INSERT INTO bookauthor (author_id, isbn, author_order, royaltyshare) VALUES(486, '1-9999-9999-x', 1, '1.00');
INSERT INTO bookauthor (author_id, isbn, author_order, royaltyshare) VALUES(712, '1-2222-2222-x', 1, '1.00');
INSERT INTO bookauthor (author_id, isbn, author_order, royaltyshare) VALUES(172, '1-3333-3333-x', 1, '1.00');
INSERT INTO bookauthor (author_id, isbn, author_order, royaltyshare) VALUES(213, '1-1032-1032-x', 2, '0.40');
INSERT INTO bookauthor (author_id, isbn, author_order, royaltyshare) VALUES(238, '1-1035-1035-x', 1, '1.00');
INSERT INTO bookauthor (author_id, isbn, author_order, royaltyshare) VALUES(213, '1-2075-2075-x', 1, '1.00');
INSERT INTO bookauthor (author_id, isbn, author_order, royaltyshare) VALUES(998, '1-2091-2091-x', 1, '0.50');
INSERT INTO bookauthor (author_id, isbn, author_order, royaltyshare) VALUES(899, '1-2091-2091-x', 2, '0.50');
INSERT INTO bookauthor (author_id, isbn, author_order, royaltyshare) VALUES(998, '1-2106-2106-x', 1, '1.00');
INSERT INTO bookauthor (author_id, isbn, author_order, royaltyshare) VALUES(722, '1-3021-3021-x', 1, '0.75');
INSERT INTO bookauthor (author_id, isbn, author_order, royaltyshare) VALUES(899, '1-3021-3021-x', 2, '0.25');
INSERT INTO bookauthor (author_id, isbn, author_order, royaltyshare) VALUES(807, '1-3218-3218-x', 1, '1.00');
INSERT INTO bookauthor (author_id, isbn, author_order, royaltyshare) VALUES(274, '1-7832-7832-x', 1, '1.00');
INSERT INTO bookauthor (author_id, isbn, author_order, royaltyshare) VALUES(427, '1-8888-8888-x', 1, '0.50');
INSERT INTO bookauthor (author_id, isbn, author_order, royaltyshare) VALUES(846, '1-8888-8888-x', 2, '0.50');
INSERT INTO bookauthor (author_id, isbn, author_order, royaltyshare) VALUES(756, '1-1372-1372-x', 1, '0.75');
INSERT INTO bookauthor (author_id, isbn, author_order, royaltyshare) VALUES(728, '1-1372-1372-x', 2, '0.25');
INSERT INTO bookauthor (author_id, isbn, author_order, royaltyshare) VALUES(728, '1-1111-1111-x', 1, '0.60');
INSERT INTO bookauthor (author_id, isbn, author_order, royaltyshare) VALUES(267, '1-1111-1111-x', 2, '0.40');
INSERT INTO bookauthor (author_id, isbn, author_order, royaltyshare) VALUES(672, '1-7777-7777-x', 1, '0.40');
INSERT INTO bookauthor (author_id, isbn, author_order, royaltyshare) VALUES(267, '1-7777-7777-x', 2, '0.30');
INSERT INTO bookauthor (author_id, isbn, author_order, royaltyshare) VALUES(472, '1-7777-7777-x', 3, '0.30');
INSERT INTO bookauthor (author_id, isbn, author_order, royaltyshare) VALUES(648, '1-4203-4203-x', 1, '1.00');



INSERT INTO bookeditor (editor_id, isbn) VALUES(0, 'ISBN');
INSERT INTO bookeditor (editor_id, isbn) VALUES(2, '1-1111-1111-x');
INSERT INTO bookeditor (editor_id, isbn) VALUES(2, '1-2091-2091-x');
INSERT INTO bookeditor (editor_id, isbn) VALUES(2, '1-2106-2106-x');
INSERT INTO bookeditor (editor_id, isbn) VALUES(3, '1-1372-1372-x');
INSERT INTO bookeditor (editor_id, isbn) VALUES(3, '1-3021-3021-x');
INSERT INTO bookeditor (editor_id, isbn) VALUES(3, '1-7832-7832-x');
INSERT INTO bookeditor (editor_id, isbn) VALUES(3, '1-8888-8888-x');
INSERT INTO bookeditor (editor_id, isbn) VALUES(5, '1-1032-1032-x');
INSERT INTO bookeditor (editor_id, isbn) VALUES(5, '1-1372-1372-x');
INSERT INTO bookeditor (editor_id, isbn) VALUES(5, '1-2222-2222-x');
INSERT INTO bookeditor (editor_id, isbn) VALUES(5, '1-3333-3333-x');
INSERT INTO bookeditor (editor_id, isbn) VALUES(5, '1-5555-5555-x');
INSERT INTO bookeditor (editor_id, isbn) VALUES(5, '1-9999-9999-x');
INSERT INTO bookeditor (editor_id, isbn) VALUES(7, '1-1111-1111-x');
INSERT INTO bookeditor (editor_id, isbn) VALUES(7, '1-2091-2091-x');
INSERT INTO bookeditor (editor_id, isbn) VALUES(7, '1-3218-3218-x');
INSERT INTO bookeditor (editor_id, isbn) VALUES(7, '1-7777-7777-x');
INSERT INTO bookeditor (editor_id, isbn) VALUES(8, '1-3021-3021-x');
INSERT INTO bookeditor (editor_id, isbn) VALUES(8, '1-4203-4203-x');
INSERT INTO bookeditor (editor_id, isbn) VALUES(8, '1-7777-7777-x');
INSERT INTO bookeditor (editor_id, isbn) VALUES(8, '1-8888-8888-x');
INSERT INTO bookeditor (editor_id, isbn) VALUES(9, '1-1032-1032-x');
INSERT INTO bookeditor (editor_id, isbn) VALUES(9, '1-1035-1035-x');
INSERT INTO bookeditor (editor_id, isbn) VALUES(9, '1-2075-2075-x');
INSERT INTO bookeditor (editor_id, isbn) VALUES(9, '1-7777-7777-x');




INSERT INTO editor (editor_id, ssn, lastname, firstname, phone, editor_position, salary) VALUES(5, '955-72-3567', 'Penny', 'Anne', '801 826-0752', 'Managing Editor', '108000.00');
INSERT INTO editor (editor_id, ssn, lastname, firstname, phone, editor_position, salary) VALUES(9, '888-46-2035', 'Jones', 'Albert', '801 826-0752', 'Copy Editor', '77000.00');
INSERT INTO editor (editor_id, ssn, lastname, firstname, phone, editor_position, salary) VALUES(2, '722-51-5454', 'Lance', 'Mike', '219 547-9982', 'Project Editor', '88000.00');
INSERT INTO editor (editor_id, ssn, lastname, firstname, phone, editor_position, salary) VALUES(7, '807-91-6654', 'Parry', 'Sylvia', '301 946-8853', 'Managing Editor', '105000.00');
INSERT INTO editor (editor_id, ssn, lastname, firstname, phone, editor_position, salary) VALUES(3, '793-72-1158', 'Smith', 'Steve', '707 448-4982', 'Copy Editor', '76000.00');
INSERT INTO editor (editor_id, ssn, lastname, firstname, phone, editor_position, salary) VALUES(8, '714-80-9391', 'MacDonald', 'Ron', '415 354-7128', 'Project Editor', '87000.00');



INSERT INTO publisher (pub_id, name, address, city, state) VALUES(2, 'Binder and Smith', '2 2nd Ave.', 'New York', 'NY');
INSERT INTO publisher (pub_id, name, address, city, state) VALUES(3, 'All Techo Books', '3 3rd Dr.', 'Cupertino', 'CA');
INSERT INTO publisher (pub_id, name, address, city, state) VALUES(1, 'Sunshine Publishers', '1 1st St', 'Berkeley', 'CA');
+17 −0
Changes for Introduction to MySQL - Working Files/Chapter 2/WAMP.html: 17 added lines, 0 removed lines.
Original line number Diff line number Diff line
<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>WAMP Instructions</title>
</head>

<body style="background-color: silver">
	<div style="position: absolute; left: 50px; top: 50px;">
		<img src="start_wamp.jpg" border="2">
    </div>

    <div style="position: absolute; left: 550px; top: 50px;">
			<img src="open_phpmyadmin.jpg" border="2">
       </div>
</body>
</html>
+265 −0
Changes for Introduction to MySQL - Working Files/Chapter 2/chapter2_sql_statements.txt: 265 added lines, 0 removed lines.
Original line number Diff line number Diff line
Chapter 2 SQL Statements

SELECT * 
FROM author

SELECT * 
FROM book

SELECT title, type
FROM book

SELECT title, type
FROM book
WHERE type = 'computer'

SELECT * 
FROM publisher

SELECT name, title
FROM publisher JOIN book USING(pub_id) 


-------

CREATE TABLE employee
(
  employee_id	numeric(9)	primary key,
  lastname	varchar(40)	not null,
  firstname	varchar(40)	not null,
  dept_code	varchar(3)	null,
  salary	numeric(8,2)	null,
  hire_date	date		not null
);

SELECT *
FROM employee;


INSERT INTO employee 
  (employee_id, lastname, firstname, dept_code, salary, hire_date)
VALUES
  (1, 'Smith', 'John', 123, 90000, '2016-11-15');
  
  
INSERT INTO employee 
  (employee_id, lastname, firstname, dept_code, salary, hire_date)
VALUES
  (2, 'Perry', 'Steve', 123, 80000, '2017-01-22');
  
INSERT INTO employee 
  (employee_id, lastname, firstname, dept_code, salary, hire_date)
VALUES
  (3, 'Jones', 'Jones', 234, 80000, '2017-01-22');
  

SELECT lastname, firstname, dept_code, salary, hire_date
FROM employee
ORDER BY lastname;


UPDATE employee
  SET salary = 95000
WHERE employee_id = 1;


SELECT lastname, firstname, dept_code, salary, hire_date
FROM employee
ORDER BY lastname;


CREATE TABLE department
(
  dept_code	numeric(3)	primary key,
  dept_name	varchar(40)	not null
);

INSERT INTO department 
  (dept_code, dept_name)
VALUES
  (123, 'Payroll');
  
  
INSERT INTO department 
  (dept_code, dept_name)
VALUES
  (234, 'Accounting');
  
  
SELECT *
FROM department;


SELECT dept_name, lastname, firstname 
FROM department JOIN employee USING(dept_code)
ORDER BY dept_name, lastname, firstname;
  

DELETE FROM employee
WHERE employee_id = 2;

SELECT *
FROM employee;


DROP TABLE employee;

SELECT *
FROM employee;



-------


CREATE TABLE Syntax (simplified):

	CREATE TABLE table_name
	(
	   column-1   datatype/size   constraint,
	   column-2   datatype/size   constraint,
	   ...
	   column-1   datatype/size   constraint
	)


CREATE TABLE employee
(
  employee_id	numeric(9)	primary key,
  lastname	varchar(40)	not null,
  firstname	varchar(40)	not null,
  dept_code	varchar(3)	null,
  salary	numeric(8,2)	null,
  hire_date	date		not null
)


DROP TABLE employee;


CREATE TABLE bookauthor
(
  author_id numeric(11) not null,
  isbn varchar(13) not null,
  author_order numeric(11) not null,
  royaltyshare numeric(5,2),
  PRIMARY KEY (author_id, isbn)
)




CREATE INDEX Syntax:

	CREATE [UNIQUE] INDEX index-name
		ON table-name   (column-name [,column-name...] );


CREATE UNIQUE INDEX author_ssn_idx
  ON author (ssn)


CREATE  INDEX author_name_idx
  ON author (lastname, firstname)


DROP INDEX author_ssn_idx ON author


DROP INDEX author_name_idx ON author




ALTER TABLE Command Syntax:

	ALTER TABLE tablename
   		ADD | MODIFY | DROP COLUMN | column_name (definition)


ALTER TABLE employee
  MODIFY lastname varchar(80);
	
	
ALTER TABLE employee
  ADD phone numeric(10);
	

ALTER TABLE author
  DROP COLUMN (phone);


----

INSERT Syntax

	INSERT INTO table_name
		[ (column_1, column_2, etc.) ]
	VALUES
		(constant_1, constant_2, etc.)
		
		

INSERT INTO publisher(pub_id, name, address, city, state) 
VALUES (5, 'Jardin, Inc.', '55th Avenue', 'Camden', 'NJ');



INSERT INTO publisher
	(pub_id, name)
VALUES
	(7, 'Healthtext');	
	
	
----




UPDATE Syntax:

	UPDATE table_name
	    SET column_name1 = expression1,
		column_name2 = expression2...
	[ WHERE search_conditions ]


UPDATE book
  SET price = 17.99;


UPDATE book
  SET price = 19.99
WHERE price = 29.99


UPDATE book
  SET price = 17.99
WHERE title = "Analyzing the Obsessive";


UPDATE book
  SET price = price * 2,
      advance = advance + 1000
WHERE ytd_sales > 10000;



----


DELETE SYNTAX:
 
 	DELETE FROM table_name
	  [WHERE search_conditions];
	  
	
DELETE FROM book;
	
DELETE FROM book
WHERE price = 2.99;

	 
DELETE FROM author 
WHERE city 'Oakland' AND state = 'CA'
+40.1 KiB
Loading image diff...
Loading