Question

3. Write a script that adds rows to the database that you created in exercise 2....

3. Write a script that adds rows to the database that you created in exercise 2. Add two rows to the Users and Products tables. Add three rows to the Downloads table: one row for user 1 and product 2; one row for user 2 and product 1; and one row for user 2 and product 2. Use the SYSDATE function to insert the current date into the download_date column. Use the sequences created in the previous exercise to get the values for the user_id, download_id, and product_id columns. Write a SELECT statement that joins the three tables and retrieves the data from these tables like this: Sort the results by the email address in descending sequence and the product name in ascending sequence. 4. Write an ALTER TABLE statement that adds two new columns to the Products table created in exercise 2. Add one column for product price that provides for three digits to the left of the decimal point and two to the right. This column should have a default value of 9.99. Add one column for the date and time that the product was added to the database. 5. Write an ALTER TABLE statement that modifies the Users table created in exercise 2 so the first_name column can store NULL values and can store a maximum of 20 characters. Code an UPDATE statement that inserts a NULL value into this column. It should work since this column now allows NULL values. Code another UPDATE statement that attempts to insert a first name that’s longer than 20 characters. It should fail due to the length of the column.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1.

use my_guitar_shop;

CREATE INDEX index_zipcode ON customers(zip_code);

Screenshot of execution:

Query 1 × 1use my_guitar_shop; 2CREATE INDEX index zipcode ON customers (zip code); Output Action Output Time Action Message

2.

drop database my_web_db;

create database my_web_db;

use my_web_db;

Screenshot of execution:

Limit to 1000 rows 1 drop database my_web_db; 2create database my_web_db; 3use my_web_db; 4 5 Output | Action Output Time Mes

CREATE TABLE USERS
(
user_id int Primary key NOT NULL,
email_address varchar(100),
first_name varchar(45),
last_name varchar(45)
);

CREATE TABLE PRODUCTS
(
product_id int Primary key NOT NULL,
product_name varchar(20)
);

CREATE TABLE DOWNLOADS
(
download_id int Primary key NOT NULL,
user_id int REFERENCES users(user_id),
download_date datetime,
filename varchar(50),
product_id int REFERENCES products(product_id)
);

Screenshot of execution:

Limit to 1000 rows * 1 · CREATE TABLE USERS 2 user id int Primary key NOT NULL email address varchar (100 5 first name varcha

3.

Screenshot of execution:

Limit to 1000 rows 1insert into USERS values (100, johnsmith@gmail.com, John, Smith) 2insert into USERS values (101, jan

USERS table: Limit to 1000 rows 1select from USERS; 2 3 4 Filter Rows: Result Grid Edit: user id email address first name la

Limit to 1000 rows 1select from DOWNLOADS; 2 4 Result Grid| ElE Filter Rows: | Wrap Cel Content: 61 田 Edit: t: download id us

Query to that joins the three tables and retrieves the data:

select email_address, first_name, last_name, download_date, filename, product_name
from USERS, PRODUCTS, DOWNLOADS
where USERS.user_id=DOWNLOADS.user_id
and PRODUCTS.product_id=DOWNLOADS.product_id;

Output:

Limit to 1000 rows 1select email_address, first_name, last_name, download date, filename, product_name 2 from USERS, PRODUCTS

SELECT statement that joins the three tables and retrieves the data. Sort the results by the email address in descending sequence and the product name in ascending sequence

select email_address, first_name, last_name, download_date, filename, product_name
from USERS, PRODUCTS, DOWNLOADS
where USERS.user_id=DOWNLOADS.user_id
and PRODUCTS.product_id=DOWNLOADS.product_id
order by email_address desc, product_name asc;

Output:

gQua lunt to 1000 rows , 1select email_address, first_name, last_name, download_date, 2 from USERS, PRODUCTS, DOWNLOADS 3 whe

4.

ALTER TABLE PRODUCTS

ADD price real(5,2) default 9.99,

ADD dateAdded datetime;

Screenshot of execution:

Query 1 × f A01 8100冏1 層?!! Limit to 1000 rows 1 ▼| 1· ALTER TABLE PRODUCTS 2 ADD price real(5,2) default 9.99, 3 ADD dateAdd

5.

ALTER TABLE USERS

MODIFY first_name varchar(20) NULL;

Screenshot of execution:

Query 1 × Limit to 1000 rows 1 ALTER TABLE USERS first-name varchar(20) MODIFY NULL; Output Action Output Action 1 12:53:17 A

Add a comment
Know the answer?
Add Answer to:
3. Write a script that adds rows to the database that you created in exercise 2....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 2. Write a script that implements the following design: In the Downloads table, the user_id and...

    2. Write a script that implements the following design: In the Downloads table, the user_id and product_id columns are the foreign keys. Create these tables in the ex schema. Create the sequences for the user_id, download_id, and product_id columns. Include a PL/SQL script to drop the table or sequence if it already exists. Include any indexes that you think are necessary. 3. Write a script that adds rows to the database that you created in exercise 2. Add two rows...

  • SQL Homework exercises: 1. Write INSERT statements that add two rows to the Members table for...

    SQL Homework exercises: 1. Write INSERT statements that add two rows to the Members table for member IDs 1 and 2, two rows to the Groups table for group IDs 1 and 2, and three rows to the Group_Membership table: one row for member 1 and group 2; one for member 2 and group 1; and one for member 2 and group 2. Then, write a SELECT statement that joins the three tables and retrieves the group name, member last...

  • 1. Write a script that creates a user-defined database role named OrderEntry in the MyGuitarShop database....

    1. Write a script that creates a user-defined database role named OrderEntry in the MyGuitarShop database. Give INSERT and UPDATE permission to the new role for the Orders and OrderItems table. Give SELECT permission for all user tables. 2. Write a script that (1) creates a login ID named “RobertHalliday” with the password “HelloBob”; (2) sets the default database for the login to the MyGuitarShop database; (3) creates a user named “RobertHalliday” for the login; and (4) assigns the user...

  • 1. Write a script that creates a user-defined database role named OrderEntry in the MyGuitarShop database....

    1. Write a script that creates a user-defined database role named OrderEntry in the MyGuitarShop database. Give INSERT and UPDATE permission to the new role for the Orders and OrderItems table. Give SELECT permission for all user tables. 3) Write a script that uses dynamic SQL and a cursor to loop through each row of the Administrators table and (1) create a login ID for each row in that consists of the administrator�s first and last name with no space...

  • Question 32 Which view would you use to see only the tables you have created ALL_TABLES...

    Question 32 Which view would you use to see only the tables you have created ALL_TABLES USER_TABLES USER_TABS ALL_OBJECTS 2 points Question 33 Which script will you execute to create new user DAVE and give him the ability to connect to the database and the ability to create tables, sequences, and procedures? CREATE USER dave IDENTIFIED BY dave18; GRANT create table, create sequence, create procedure TO dave; CREATE USER dave IDENTIFIED BY dave18; GRANT create session, create table, create sequence,...

  • 1. Write an INSERT statement that adds this row to the Categories table: CategoryName: Brass Code...

    1. Write an INSERT statement that adds this row to the Categories table: CategoryName: Brass Code the INSERT statement so SQL Server automatically generates the value for the CategoryID column. 2. Write an UPDATE statement that modifies the row you just added to the Categories table. This statement should change the Category Name column to “Woodwinds”, and it should use the CategoryID column to identify the row. 3.Write an INSERT statement that adds this row to the Products table: ProductID:...

  • this is sql developer question I just need the format of how to answer question! Create...

    this is sql developer question I just need the format of how to answer question! Create sequences (2) that can be used to number the member ID and group ID values starting with 3 (since you already have 1 and 2). Write an INSERT statement that adds another row to the Groups table, make up a group name. Use the NEXTVAL pseudo column to get the value for the next group ID from the sequence that you created in #5....

  • Learning Objectives: Learn to define constraints on tables Lean to define primary keys and foreign keys...

    Learning Objectives: Learn to define constraints on tables Lean to define primary keys and foreign keys Exercise                                                                                In Lab 09, we will continue the practice of creating tables. You will need to write SQL statements for the tasks specified below. After you complete them, submit your SQL script (in one *.sql file) to Blackboard by 11:59pm Nov. 16 (Friday). Include your name as a comment in the SQL script submitted. The creation statement for each table is worth one point,...

  • 1.What is the return value if the user try to do the following: SELECT TRUNC (65.73,-2)...

    1.What is the return value if the user try to do the following: SELECT TRUNC (65.73,-2) FROM DUAL; Select one: a. 60 b. 00 c. 0 d. 600 2.Supposed that the user uses the ff SELECT statement: what will be the possible output. SELECT GRADE AS STUDENT MARK FROM GRADE_REPORT; Select one: a. Error because of the keyword AS. b. Error because of missing “” mark. c. Will display the column GRADE rename as STUDENT MAK d. Will display all...

  • Overview: Database management plays an integral role in nearly every area of business. Databases house customer, accoun...

    Overview: Database management plays an integral role in nearly every area of business. Databases house customer, accounting, and employee data, and these different data sets must all be efficiently managed in order to make the data accessible. Companies rely on database engineers to ensure that their records are accurate, updated, and tracked in real time. This course covers structured query language (SQL) and how it can be used to manage database schemas, manipulate data, and analyze data. For your final...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT