Question: SQL Homework exercises: exercise 2: CREATE TABLE users ( user_id int Primary key NOT NULL, email_address VARCHAR(20), first_name VARCHAR(20), last_name VARCHAR(20) ); CREATE TABLE downloads
SQL Homework exercises:
exercise 2:
CREATE TABLE users ( user_id int Primary key NOT NULL, email_address VARCHAR(20), first_name VARCHAR(20), last_name VARCHAR(20) ); CREATE TABLE downloads ( download_id int Primary key NOT NULL, user_id INT, download_date DATE, last_name VARCHAR(20), product_id INT, CONSTRAINT fk_column FOREIGN KEY(user_id) REFERENCES users(user_id), FOREIGN KEY(product_id) REFERENCES product(product_id) ); CREATE TABLE product ( product_id int Primary key NOT NULL, product_name VARCHAR(20)
SQL Homework exercises:
exercise 2:
CREATE TABLE users ( user_id int Primary key NOT NULL, email_address VARCHAR(20), first_name VARCHAR(20), last_name VARCHAR(20) ); CREATE TABLE downloads ( download_id int Primary key NOT NULL, user_id INT, download_date DATE, last_name VARCHAR(20), product_id INT, CONSTRAINT fk_column FOREIGN KEY(user_id) REFERENCES users(user_id), FOREIGN KEY(product_id) REFERENCES product(product_id) ); CREATE TABLE product ( product_id int Primary key NOT NULL, product_name VARCHAR(20) );
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 thats longer than 20 characters. It should fail due to the length of the column.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
