Guest User

Untitled

a guest
Jul 30th, 2018
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.75 KB | None | 0 0
  1. Question 1 & 2:
  2. To add data you use the INSERT INTO commands followed by the table name followed by the VALUES command and whatever data
  3. values necessary in accordance with the data types for those particular columns. To update data you use the UPDATE command
  4. followed by the table name and then the SET command and the data types you would like to update by their column name with
  5. an = and then the value. You can additionally have a WHERE clause to set a conditional statement for the the particular data
  6. you are targeting to update. To delete you can use the DELETE FROM commands followed by the table name and WHERE command with
  7. conditionals and also a AND command to add additional conditionals after the where command. You can use the ALTER TABLE
  8. command followed by the table name and ADD COLUMN or DROP COLUMN followed by a text description of why. You can set a default
  9. value for that by using the SET DEFAULT command followed by what you want the default to be.
  10.  
  11. Question 3:
  12. There are Monetary Types which could be used to store data in a format of money specific to the currency, you can adjust
  13. how many float decimals you want. There is a boolean type which would be a true or false. There is an integer type which
  14. will take a four byte integer.
  15.  
  16. Question 4:
  17. CREATE TABLE invitations (
  18. id integer,
  19. firstname text,
  20. lastname text,
  21. RSVP boolean,
  22. guests real,
  23. meals numeric,
  24. );
  25.  
  26. ALTER TABLE invitations ADD COLUMN (thankyousent boolean);
  27.  
  28. ALTER TABLE invitations DROP COLUMN meals;
  29.  
  30. ALTER TABLE invitations ADD COLUMN (tablenumber real);
  31.  
  32. DROP TABLE invitations
  33.  
  34. Question 5:
  35.  
  36. CREATE TABLE books (
  37. ISBN varchar(13),
  38. title text,
  39. author text,
  40. genre text,
  41. publishing_date date,
  42. copies real,
  43. available_copies real,
  44. );
  45.  
  46. INSERT INTO books (ISBN, title, author, genre)
  47. VALUES (9782846664417, 'Into The Wild', 'Jon Krakauer', 'non-fiction' ),
  48. (9786612984297, 'Eloquent Ruby', 'Russ Olsen', 'education' ),
  49. (9781617291692, 'The well grounded rubyist', 'David A. Black', 'education');
  50.  
  51. UPDATE books SET available_copies=0 WHERE ISBN=9781617291692;
  52.  
  53. DELETE FROM books WHERE ISBN=9782846664417 AND title='Into The Wild';
  54.  
  55. Question 6:
  56.  
  57. CREATE TABLE spacecrafts (
  58. id integer,
  59. name text,
  60. year_launched date(year),
  61. country_origin text,
  62. mission_desc text,
  63. orbiting_body text,
  64. operating boolean,
  65. miles_from_earth integer,
  66. );
  67.  
  68. INSERT INTO spacecrafts (id, name, year_launched, country_origin, mission_desc, orbiting_body, operating, miles_from_earth)
  69. VALUES (1, 'The Sustainiac', 1965, 'USA', 'Jupiter', true, 3232323),
  70. (2, 'The Fat Tire', 1204, 'Mesopotamia', 'Uranus',true, 888888888888),
  71. (3, 'Wumbo', 6, 'A rock', 'A Star', true, 1231215454);
  72.  
  73. DELETE FROM spacecrafts WHERE id=1; UPDATE FROM spacecrafts SET operating=false WHERE id=1;
  74.  
  75. Question 7:
  76.  
  77. CREATE TABLE emails (
  78. id integer,
  79. email_subject text,
  80. sender text,
  81. additional_recipients text,
  82. email_body text,
  83. timestamp timestamp,
  84. read boolean,
  85. email_chain_id integer
  86. );
  87.  
  88. INSERT INTO emails (id, email_subject, sender, additional_recipients, email_body, timestamp, read, email_chain_id)
  89. VALUES (1, 'hi', 'bob@gmail.com', 'bill@generic.com', 'I lost my way', Tue 01-01-2009 6:00, false, 123),
  90. (2, 'bye', 'bob2@gmail.com', 'phil@lipshead.com', 'I think I'm lost.', Tue 01-01-2009 6:01, false, 1234),
  91. (2, 'yo', 'dansmith@email.com', 'flat@head.com', 'Hey I'm a shark and a screwdriver.', Tue 01-01-2009 6:02, true, 123456);
  92.  
  93. DELETE FROM emails WHERE id=1;
  94.  
  95. UPDATE emails SET read=false WHERE id=2;
Add Comment
Please, Sign In to add comment