Sei sulla pagina 1di 3

Robert Chrisman

CIS305-T301
Week 4 Assignment and T-SQL
Week 4 Assignment:

Assignment Week 3 SQL:


Use the cis305 database you previously created. Create a new table named
PRODUCT. The product table will have two attributes;
product ID as integer, not null, and a primary key constraint set to unique.
product description as varchar(30), not null specification.
When you have created the new table, copy and paste your T-SQL into your
assignment submission.

use cis305;

if object_id('dbo.PRODUCT', 'U') is not null


drop table dbo.PRODUCT;
CREATE TABLE dbo.PRODUCT
(
Product_ID
int
PRIMARY KEY (Product_ID),
Product_Des
);

NOT NULL,
varchar(30)

NOT NULL

Next, write T-SQL to alter the booth table and the machine table to add a product
id attribute, type integer to each table. When the fields have been successfully
added to each table, copy and paste your T-SQL into your assignment
submission.
use cis305;
ALTER TABLE dbo.Booth
ADD Product_ID int

NOT NULL;

ALTER TABLE dbo.Machine


ADD Product_ID int

NOT NULL;

Lastly, use the following two sets of insert statements to insert data into the
product table and the booth table.
use cis305;

insert into dbo.product(Product_ID, product_des)


values(1, 'Chips');
insert into dbo.product(product_id, product_des)
values(2, 'Cola')
insert into dbo.product(product_id, product_des)
values(3, 'Energy Drink');
insert into dbo.product(product_id, product_des)
values(4, 'Chocolate Bar');
go
insert into dbo.Booth(booth_product, booth_price, product_id)
values('Chips', 1.5, 1);
insert into dbo.Booth(booth_product, booth_price, product_id)
values('Cola', 1.25, 2);
insert into dbo.Booth(booth_product, booth_price, product_id)

values('Energy Drink', 2, 3);

QUERY OUTPUT:
(1 row(s) affected)
(1 row(s) affected)
(1 row(s) affected)
(1 row(s) affected)
(1 row(s) affected)
(1 row(s) affected)
(1 row(s) affected)

Using the insert statements for the booth table, write insert statements to insert the
following values into the machine table for the machine product, machine price, and
product id fields respectively:

Potrebbero piacerti anche