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.
1.
use my_guitar_shop;
CREATE INDEX index_zipcode ON customers(zip_code);
Screenshot of execution:
2.
drop database my_web_db;
create database my_web_db;
use my_web_db;
Screenshot of execution:
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:
3.
Screenshot of execution:
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:
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:
4.
ALTER TABLE PRODUCTS
ADD price real(5,2) default 9.99,
ADD dateAdded datetime;
Screenshot of execution:
5.
ALTER TABLE USERS
MODIFY first_name varchar(20) NULL;
Screenshot of execution:
3. Write a script that adds rows to the database that you created in exercise 2....
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 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. 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. 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 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 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 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 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) 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, 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...