Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Question 1 & 2:
- To add data you use the INSERT INTO commands followed by the table name followed by the VALUES command and whatever data
- values necessary in accordance with the data types for those particular columns. To update data you use the UPDATE command
- followed by the table name and then the SET command and the data types you would like to update by their column name with
- an = and then the value. You can additionally have a WHERE clause to set a conditional statement for the the particular data
- you are targeting to update. To delete you can use the DELETE FROM commands followed by the table name and WHERE command with
- conditionals and also a AND command to add additional conditionals after the where command. You can use the ALTER TABLE
- command followed by the table name and ADD COLUMN or DROP COLUMN followed by a text description of why. You can set a default
- value for that by using the SET DEFAULT command followed by what you want the default to be.
- Question 3:
- There are Monetary Types which could be used to store data in a format of money specific to the currency, you can adjust
- how many float decimals you want. There is a boolean type which would be a true or false. There is an integer type which
- will take a four byte integer.
- Question 4:
- CREATE TABLE invitations (
- id integer,
- firstname text,
- lastname text,
- RSVP boolean,
- guests real,
- meals numeric,
- );
- ALTER TABLE invitations ADD COLUMN (thankyousent boolean);
- ALTER TABLE invitations DROP COLUMN meals;
- ALTER TABLE invitations ADD COLUMN (tablenumber real);
- DROP TABLE invitations
- Question 5:
- CREATE TABLE books (
- ISBN varchar(13),
- title text,
- author text,
- genre text,
- publishing_date date,
- copies real,
- available_copies real,
- );
- INSERT INTO books (ISBN, title, author, genre)
- VALUES (9782846664417, 'Into The Wild', 'Jon Krakauer', 'non-fiction' ),
- (9786612984297, 'Eloquent Ruby', 'Russ Olsen', 'education' ),
- (9781617291692, 'The well grounded rubyist', 'David A. Black', 'education');
- UPDATE books SET available_copies=0 WHERE ISBN=9781617291692;
- DELETE FROM books WHERE ISBN=9782846664417 AND title='Into The Wild';
- Question 6:
- CREATE TABLE spacecrafts (
- id integer,
- name text,
- year_launched date(year),
- country_origin text,
- mission_desc text,
- orbiting_body text,
- operating boolean,
- miles_from_earth integer,
- );
- INSERT INTO spacecrafts (id, name, year_launched, country_origin, mission_desc, orbiting_body, operating, miles_from_earth)
- VALUES (1, 'The Sustainiac', 1965, 'USA', 'Jupiter', true, 3232323),
- (2, 'The Fat Tire', 1204, 'Mesopotamia', 'Uranus',true, 888888888888),
- (3, 'Wumbo', 6, 'A rock', 'A Star', true, 1231215454);
- DELETE FROM spacecrafts WHERE id=1; UPDATE FROM spacecrafts SET operating=false WHERE id=1;
- Question 7:
- CREATE TABLE emails (
- id integer,
- email_subject text,
- sender text,
- additional_recipients text,
- email_body text,
- timestamp timestamp,
- read boolean,
- email_chain_id integer
- );
- INSERT INTO emails (id, email_subject, sender, additional_recipients, email_body, timestamp, read, email_chain_id)
- VALUES (1, 'hi', 'bob@gmail.com', 'bill@generic.com', 'I lost my way', Tue 01-01-2009 6:00, false, 123),
- (2, 'bye', 'bob2@gmail.com', 'phil@lipshead.com', 'I think I'm lost.', Tue 01-01-2009 6:01, false, 1234),
- (2, 'yo', 'dansmith@email.com', 'flat@head.com', 'Hey I'm a shark and a screwdriver.', Tue 01-01-2009 6:02, true, 123456);
- DELETE FROM emails WHERE id=1;
- UPDATE emails SET read=false WHERE id=2;
Add Comment
Please, Sign In to add comment