Question

In: Computer Science

Write a SQL script to add another table to your database. Include these fields in your...

Write a SQL script to add another table to your database. Include these fields in

your Product table:

Field Name

Description

Data Type

Sample Value

ProductID

Product ID

integer

5

ProductName

Product Name

varchar(50)

candle

Description

Product Description

varchar(255)

Bee’s wax candle

picUrl

Filename of the product’s picture

varchar(50)

candle.gif

Price

Product Price

decimal

10.99

          ProductID should be the Primary Key. It is an auto-increment field.

          The Price field stores prices to 7 significant digits and to 2 decimal places.

          Add at least ten records to the Product table using INSERT.

Solutions

Expert Solution

Below is the create Product table script

As given The Price field stores prices to 7 significant digits and to 2 decimal places, so price column in create statement will be Price DECIMAL(7, 2),

CREATE TABLE IF NOT EXISTS Product (
    ProductID int NOT NULL AUTO_INCREMENT,
    ProductName varchar(50) NOT NULL,
    Description varchar(255) NOT NULL,
    picUrl varchar(50) NOT NULL,
    Price DECIMAL(7, 2),
    PRIMARY KEY (ProductID)
);

Below are the insert statement for inserting 10 Reccords. As primary key is auto increment we don't need to include in insert statement. Primary key will be generated automatically.

Also tried insert statement with price - 22222.1777. As Price column is 7 significant digits and to 2 decimal places hence price will be saved as 22222.18

INSERT INTO Product (ProductName,Description,picUrl,Price) VALUES ('Product1','This is sample product 1', 'product1.gif', 22.19);
INSERT INTO Product (ProductName,Description,picUrl,Price) VALUES ('Product2','This is sample product 2', 'product2.gif', 145.77);
INSERT INTO Product (ProductName,Description,picUrl,Price) VALUES ('Product3','This is sample product 3', 'product3.gif', 999.99);
INSERT INTO Product (ProductName,Description,picUrl,Price) VALUES ('Product4','This is sample product 4', 'product4.gif', 1245.41);
INSERT INTO Product (ProductName,Description,picUrl,Price) VALUES ('Product5','This is sample product 5', 'product5.gif', 11455.65);
INSERT INTO Product (ProductName,Description,picUrl,Price) VALUES ('Product6','This is sample product 6', 'product6.gif', 21455.33);
INSERT INTO Product (ProductName,Description,picUrl,Price) VALUES ('Product7','This is sample product 7', 'product7.gif', 99.66);
INSERT INTO Product (ProductName,Description,picUrl,Price) VALUES ('Product8','This is sample product 8', 'product8.gif', 1.68);
INSERT INTO Product (ProductName,Description,picUrl,Price) VALUES ('Product9','This is sample product 9', 'product9.gif', 42.190);
INSERT INTO Product (ProductName,Description,picUrl,Price) VALUES ('Product10','This is sample product 10', 'product10.gif', 22222.1777);

Below is the screenshot of inserted data into Product table

Select * from Product

Note - Above queries are for MySQL. And tested against MySQL database.


Related Solutions

Using SQL create a new database called school_app. Create a student table with fields id (auto...
Using SQL create a new database called school_app. Create a student table with fields id (auto increment), first_name, last_name. Create a course table with fields id (auto increment), course code (such as ITC or MTH), and course number (such as 100 or 295). Note that the relationship between student and course is many-to-many (n:m). Create a join table called student_course that implements the n:m relationship with fields id (auto increment), student_id, course_id, and grade (which has values 0, 1, 2,...
Write the DML code to add the first row of each table to the database.
Write the DML code to add the first row of each table to the database.
Summary Lewis wants you to write another script that shows a table of events at the...
Summary Lewis wants you to write another script that shows a table of events at the Lyman Hall Theater over the next two weeks from the current date. He has already created three arrays for use with the script: The eventDates array containing a list of dates and times at which theater events are scheduled. The eventDescriptions array containing the description of those events. The eventPrices array containing the admission prices of those events. Lewis has already written the page...
Create a new SQL table in your phpMyAdmin account that collects the following fields (columns) -  (10...
Create a new SQL table in your phpMyAdmin account that collects the following fields (columns) -   1) The name of a medicine, sanitizer, or tip/trick for protecting yourself against transmission or fight the disease - STRING 2) The amount of money the item costs - NUMBER 3) The UPC code of the item - NUMBER 4) Manufacturing country of the item - STRING Connect to the SQL database with your HTML code, and make sure to show the results of...
Part 2: Use MySQL Workbench to add a table to your database on the class server...
Part 2: Use MySQL Workbench to add a table to your database on the class server and name the table “Person”. Include these fields in the Person table: Field Name Description Data Type Sample Value LoginID User’s login name varchar(10) Bob FirstName User’s first name varchar(50) Bob LastName User’s last name varchar(50) Barker picUrl Filename of the user’s picture varchar(50) bob.gif Bio User’s biography varchar(255) Bob is the best! LoginID should be the Primary Key of the table. Add at...
tableA is a table in a relational database with a composite prime key consisting of fields...
tableA is a table in a relational database with a composite prime key consisting of fields F1 and F2. You have determined that tableA is 1NF. There are four other fields in tableA. Two of them, F10 and F12, are functionally determined by F1. The other two, F50 and F55, are functionally determined by F2. Because all fields are functionally determined by at least a portion of the key, is tableA 2NF?   If you believe the table is not yet...
You have a table for a membership database that contains the following fields: MemberLastName,
You have a table for a membership database that contains the following fields: MemberLastName, MemberFirstName, Street, City, State, ZipCode, and InitiationFee. There are 75,000 records in the table. What indexes would you create for the table, and why would you create these indexes?
Write a Java PATRON class with fields that reflect the structure of your patrons table. Write...
Write a Java PATRON class with fields that reflect the structure of your patrons table. Write a java FACTORY class with these two methods: getPatron (String patronID) that returns a patron object for the requested patronID. The patron object that is returned should have field values that were loaded from the database using JDBC. updatePatron(Patron PatronToUpdate) that returns a string indicating whether the patron object that was passed in was successfully updated in the database or not. The method should...
Write the SQL queries that accomplish the following tasks using the AP Database 9. Write a...
Write the SQL queries that accomplish the following tasks using the AP Database 9. Write a select statement to show the invoicelineitemdescriptions that have the total invoicelineitemamount >1000 and the number of accountno is >2. 10. Write a select statement that returns the vendorid, paymentsum of each vendor, and the number of invoices of each vendor, where paymentsum is the sum of the paymentotal column. Return only the top ten vendors who have been paid the most and the number...
SQL Code: Write a script that creates and calls a stored procedure named test. This procedure...
SQL Code: Write a script that creates and calls a stored procedure named test. This procedure should identify all of the prime numbers less than 100. (A prime number is an integer that can't be divided by another integer other than 1 and itself.) Then, it should display a string variable that includes the prime numbers like this: 2 1 3 1 5 1 7 1 1 1 1 1 3 1 1 7 1 1 9 1 2 3...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT