Add three rows to the Downloads table. Add data for all the fields. One row for
ID: 3856749 • Letter: A
Question
Add three rows to the Downloads table. Add data for all the fields.
One row for user 1 and product 1
One row for user 2 and product 1
One row for user 2 and product 2
Use the NOW function to insert the current date and time into the download_date column.
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.
1. 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.
2. Write an ALTER TABLE statement that modifies the Users table created in exercise 2 so the first_name column cannot store NULL values and can store a maximum of 20 characters.
Code an UPDATE statement that attempts to insert a NULL value into this column. It should fail due to the NOT NULL constraint.
Code another UPDATE statement that attempts to insert a first name that’s longer than 20 characters. It should fail due to the length.
I am getting an error when I try to do the following:
mysql> insert into Downloads values('user 1','product 2',GETDATE());
ERROR 1136 (21S01): Column count doesn't match value count at row 1
Explanation / Answer
Issue is coming because insert statement columns are not specified and there is mismatch between the total columns in the table and values you are inserting. Try to create an insert statement which has all the columns and their values.
In the insert statement, specify the column names explicitly for the values that are being passed.
Eg.
If there are any more columns which cannot be null then add those columns in the above statement.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.