You are on page 1of 5

ASSIGNMENT WEEK 2 1

Assignment Week 2

Eduardo Torres

Bellevue University: CIS605-T401


ASSIGNMENT WEEK 2 2

YOU ARE TO USE SQL COMMANDS TO BUILD THESE UNLESS OTHERWISE NOTED.

1. Create a new database named CIS605. Assign a SIZE of 10, MAXSIZE of 100, FILEGROWTH of 5. For
the log file (LDF) assign a SIZE of 40, MAXSIZE of 100, FILEGROWTH of 10. When you run the SQL and
the database is created copy and paste the SQL and the Messages output to your assignment Word
document.

CREATE DATABASE [CIS605]


CONTAINMENT = NONE
ON PRIMARY
(NAME = 'CIS605', FILENAME = 'C:\Databases\CIS605.mdf', SIZE = 10, MAXSIZE = 100,
FILEGROWTH = 5)
LOG ON
(NAME = 'CIS605_log', FILENAME = 'C:\Databases\CIS605_log.ldf', SIZE = 40, MAXSIZE = 100,
FILEGROWTH = 10)
GO

Commands completed successfully.

Completion time: 2020-11-11T22:10:09.5755776-08:00

*****
Create a table for the CIS605 database called employee with the following columns:
integer employee number
character first name
character last name
character department number (4 digits)
Specify all four columns as NOT NULL
Add a constraint that sets the employee number as the primary key.

When you run the SQL and the database is created copy and paste the SQL and the Messages output
to your assignment Word document.

CREATE TABLE Employee


(
EmployeeNumber int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255) NOT NULL,
DepartmentNumber varchar(4) NOT NULL,
CONSTRAINT PK_EmployeeNumber PRIMARY KEY (EmployeeNumber)
)

Commands completed successfully.

Completion time: 2020-11-11T22:13:18.7786292-08:00

*****
Use the select statement you used for week 1 to display the database name, file type, logical file
name, physical file, and state for cis605. copy and paste the SQL statement and the Results to your
assignment Word document.
ASSIGNMENT WEEK 2 3

SELECT DB_NAME(database_id) AS DatabaseName, type_desc AS FileType, name AS


LogicalFileName, physical_name AS PhysicalFileName, state_desc as State
FROM sys.master_files AS mf WHERE DB_NAME(database_id) = 'CIS605';

2. Drop the primary key constraint from the employee table.

ALTER TABLE Employee DROP CONSTRAINT PK_EmployeeNumber;

Commands completed successfully.

Completion time: 2020-11-11T22:15:14.2667242-08:00

*****

USE THE ADVENTUREWORKS2012 DATABASE FOR THE FOLLOWING:

3. Write a select statement to select the person type, last name, email promotion from persons and
the country region code from the state province. Select only records where the email promotion code
equals 2, sort by last name, offset 20 rows and only fetch 10 rows.

SELECT Per.PersonType, Per.LastName, Per.EmailPromotion, st.CountryRegionCode FROM


(SELECT p.PersonType , p.LastName , p.EmailPromotion, j.StateProvinceID FROM
Person.Person AS p
JOIN (Select Adr.StateProvinceID, Addr.AddressID, Addr.BusinessID FROM Person.Address AS
Adr
JOIN (SELECT Ad.AddressID AS AddressID, Ad.BusinessEntityID AS BusinessID FROM
Person.Person AS p
JOIN Person.BusinessEntityAddress Ad
ON Ad.BusinessEntityID = p.BusinessEntityID) AS Addr
ON Adr.AddressID = Addr.AddressID) AS j
ON p.BusinessEntityID = j.BusinessID) AS Per
JOIN Person.StateProvince AS st
ON Per.StateProvinceID = st.StateProvinceID
WHERE Per.EmailPromotion = 2
ORDER BY Per.LastName ASC
OFFSET 20 ROWS
FETCH NEXT 10 ROWS ONLY;
ASSIGNMENT WEEK 2 4

*****

4. Write an INNER JOIN query on two tables. The two tables are the production product table and the
sales shopping cart item table joined on product ID. The required columns in the report are product
ID, product name with a column header of ProductName, from the product table and quantity,
shopping cart item ID from the shopping cart item table. The output should resemble the example
below.

SELECT pro.ProductID , pro.Name AS ProductName , shp.Quantity , shp.ShoppingCartItemID


FROM Production.Product as pro
INNER JOIN Sales.ShoppingCartItem as shp
ON pro.ProductID=shp.ProductID;

ProductID ProductName Quantity ShoppingCartItemID


862 Full-Finger Gloves, M 3 2
881 Short-Sleeve Classic Jersey, S 4 4
874 Racing Socks, M 7 5

*****

5. Write a correlated subquery using the Production Product table, columns Name and Product
Number. The subquery table is the purchasing product vendor table and the subquery should select
only records where the minimum order quantity equals 100. The output should display the Name and
Product Number sorted by Name, offset by 0 rows, fetching only the first 10 rows.

SELECT pro.Name, pro.ProductNumber FROM Production.Product AS pro


WHERE Pro.ProductID IN (select proVen.ProductID FROM Purchasing.ProductVendor AS proVen
WHERE proVen.MinOrderQty = 100 )
ORDER BY pro.Name ASC
OFFSET 0 ROWS
ASSIGNMENT WEEK 2 5

FETCH NEXT 10 ROWS ONLY;

You might also like