Guest User

Untitled

a guest
Dec 13th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.31 KB | None | 0 0
  1. List the commands for adding, updating, and deleting data.
  2.  
  3. INSERT INTO tasks (id, responsible, description, time)
  4. VALUES
  5. (1001, ‘Donald Duck’, ‘Draft Scope Document’, 2)
  6. (1002, ‘Mickey Mouse’, ’Design Front End’, 3)
  7. (1003, ‘Donald Duck’, ‘Database Requirements’, 5)
  8. (1004, ‘Minnie Mouse’, ‘Customer Requirement’, 2)
  9. (1005, ‘Goofy’, ‘Agile & Project Mgt’, 5)
  10. (1006, ‘Goofy’, ‘Javascript program’, 2)
  11. (1007, ‘Mickey Mouse’, ‘Alpha testing’, 3)
  12. (1008, ‘Minnie Mouse’, ‘Beta Testing’, 6)
  13.  
  14. UPDATE tasks SET time=4 WHERE id=1001;
  15.  
  16. DELETE FROM tasks WHERE id=1007;
  17.  
  18.  
  19. Explain the structure for each type of command.
  20.  
  21. Adding:
  22.  
  23. INSERT INTO: Fundamental SQL for inserting a row of data
  24. tasks: the table that will have the inserted data
  25. (id, responsible, description, time): The columns that are being inserted into the table
  26. VALUES: describe the rows that will be entered that match the columns that where previously defined.
  27.  
  28.  
  29. Updating
  30. UPDATE tasks: Indicates what table will be updated using the SQL command
  31. SET defines the column – time – that will be updated, and what the value of those selected columns will be
  32. SET time=4
  33. WHERE id=1001; defines the scope of the changes – in this case, only the records where the id is equal to 1001. Since that is a single record, only that will be updated
  34.  
  35.  
  36. Deleting
  37. DELETE FROM tasks: The SQL command the indicate which table will undergo the DELETE function.
  38. WHERE id=1007: defines the scope of the records to be deleted – in this case, only the records where the id is equal to 1007. Since that is a single record, only that will be deleted
  39.  
  40. What are some of the data types that can be used in tables? Give a real-world example of each type.
  41.  
  42. Numbers, Text, Date & Time
  43. Numbers: Inventory Counts, Reorder Points, Profits, nanometers, light-years
  44.  
  45. Text: Names, Quotes, tweets
  46.  
  47. Date & Time: Date of Birth, Atomic Clock Time, Mean Time Between Failures
  48.  
  49.  
  50.  
  51. Decide how to create a new table to hold a list of people invited to a wedding dinner. The table needs to have first and last names, whether they sent in their RSVP, the number of guests they are bringing, and the number of meals (1 for adults and 1/2 for children).
  52.  
  53. Which data type would you use to store each of the following pieces of information?
  54. First and last name - test
  55. Whether they sent in their RSVP. boolean
  56. Number of guests. number
  57. Number of meals. number
  58. Write a command that creates the table to track the wedding dinner.
  59.  
  60.  
  61. CREATE TABLE guests (
  62. id integer,
  63. name text,
  64. rsvpstatus boolean,
  65. guest integer,
  66. meals number(2,1)
  67. );
  68.  
  69.  
  70. • Write a command that adds a column to track whether the guest sent a thank you card.
  71.  
  72. ALTER TABLE guests ADD COLUMN thankyou boolean;
  73.  
  74.  
  75. You have decided to move the data about the meals to another table, so write a command to remove the column storing the number meals from the wedding table.
  76.  
  77. ALTER TABLE guests DROP COLUMN meals;
  78.  
  79. The guests will need a place to sit at the reception, so write a command that adds a column for table number.
  80.  
  81. ALTER TABLE guests ADD COLUMN table integer;
  82.  
  83.  
  84. The wedding is over and we do not need to keep this information, so write a command that deletes the table numbers from the database.
  85.  
  86. ALTER TABLE guests DROP COLUMN table;
  87.  
  88. ************
  89.  
  90. Write a command to create a new table to hold the books in a library with the columns ISBN, title, author, genre, publishing date, number of copies, and available copies.
  91.  
  92. CREATE TABLE books (
  93. isbn integer,
  94. title text,
  95. author text,
  96. genre text,
  97. pubdate date,
  98. inventory integer,
  99. available integer,
  100. );
  101.  
  102.  
  103. Find three books and add their information to the table.
  104.  
  105. INSERT INTO books (isbn, title, author, genre, pudate, inventory, available)
  106. VALUES
  107. (1974617041, ‘Addicted to Hopium’, ‘Kevin Kohls’, ‘Business’, September 5, 2017, 5, 2),
  108. (9780884271956, ‘The Goal: A Process of Ongoing Improvement’, ‘Eliyahu M. Goldratt’, ‘Business & Money’, June 1, 2014, 3, 3),
  109. (1594484805, ‘Drive: The Surprising Truth About What Motivates Us’, ‘Daniel H. Pink’, ‘Motivation & Self-Improvement’, April 5, 2011, 4, 1);
  110.  
  111.  
  112.  
  113.  
  114. Someone has just checked out one of the books. Change the number of available copies to 1 fewer.
  115.  
  116. UPDATE books SET available=1 WHERE isbn=1974617041;
  117.  
  118. Now one of the books has been added to the banned books list. Remove it from the table.
  119.  
  120. DELETE FROM books WHERE isbn=9780884271956;
  121.  
  122.  
  123. Write a command to make a new table to hold spacecrafts. Information should include id, name, year launched, country of origin, a brief description of the mission, orbiting body, if it is currently operating, and its approximate miles from Earth. In addition to the table creation, provide commands that perform the following operations:
  124.  
  125. CREATE TABLE spacecrafts (
  126. id integer,
  127. name text,
  128. year date,
  129. country text,
  130. missiondescript text,
  131. orbitingbody text,
  132. operating boolean,
  133. distance numeric(6,1));
  134.  
  135.  
  136. Add three non-Earth-orbiting satellites to the table.
  137.  
  138. INSERT INTO spacecrafts
  139. VALUES (id, name, year, country, missiondescript, orbitingbody, operating, distance)
  140. (26734 ‘2001 Mars Odyssey’, 7 April 2001, 15:02:22 UTC, ‘United States’, Use spectrometers and a thermal imager to detect evidence of past or present water and ice’, ‘Mars’, TRUE, 33.9)
  141.  
  142. (10321 ‘Voyager 1’, September 5, 1977, 12:56:00 UTC, ‘United States’, ‘Flybys of Jupiter, Saturn, and Saturn's largest moon, Titan, ‘None’, TRUE, 13229.0)
  143.  
  144. (43592 ‘Parker Solar Probe, August 12, 2018, 07:31 UTC, ‘United States’, ‘Probe the outer corona of the Sun’, ‘Sun’, TRUE, 93.0)
  145.  
  146. Remove one of the satellites from the table since it has just crashed into the planet.
  147.  
  148. DELETE FROM spacecrafts WHERE id=43592;
  149.  
  150.  
  151. Edit another satellite because it is no longer operating and change the value to reflect that.
  152.  
  153. UPDATE spacecrafts SET operating = false WHERE id=43592;
  154.  
  155.  
  156.  
  157. Write a command to create a new table to hold the emails in your inbox. This table should include an id, the subject line, the sender, any additional recipients, the body of the email, the timestamp, whether or not you have read the email, and the id of the email chain it's in.
  158.  
  159.  
  160. CREATE TABLE emails (
  161. id integer,
  162. subject text,
  163. sender text,
  164. ccs text,
  165. body text,
  166. timestamp date,
  167. read boolean,
  168. chain integer);
  169.  
  170.  
  171. Also provide commands that perform the following operations:
  172.  
  173.  
  174. Add three new emails to the inbox.
  175.  
  176. INSERT INTO emails
  177. VALUES (id, subject, sender, ccs, body, timestamp, read, chain)
  178. (1001, ‘SQL Assignment’, ‘kevinkohls@gmail.com’, null, ‘Are you still up working on this SQL stuff?’, 12/13/2018 @ 4:25am (UTC), true, null)
  179.  
  180. (1002, ‘FWD:SQL Assignment’, ‘kevinkohs@gmail.com’, hsteinfeld@gmail.com, ‘Because Hailee and I are, and we are lost. Text pls’, 12/13/2018 @ 4:28am (UTC), true, 1001)
  181.  
  182. (1003, ‘Never Mind!!!’, ‘kevinkohls@gmail.com’, ‘Jen@gmail.com’, ‘Never mind. Jenifer Lawrence and I are going out for pizza. Your loss, dude.’, 12/13/2018 @ 4:31am (UTC), false, 1002)
  183.  
  184.  
  185.  
  186. You deleted one of the emails, so write a command to remove the row from the inbox table.
  187.  
  188. DELETE FROM emails WHERE id=1001;
  189.  
  190.  
  191. You started reading an email but just heard a crash in another room. Mark the email as unread before investigating the crash, so you can come back and read it later.
  192.  
  193. UPDATE emails SET read =false WHERE id=1002;
Add Comment
Please, Sign In to add comment