8000 GitHub - saghal/Database-Lab: My database lab codes
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

saghal/Database-Lab

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Database Lab

First of all, I created a database and then created and filled tables. After that I answered 3 questions:

  1. For a student who has a student number 123, show the details of the department where he or she is studying.
  1. Write a 'select' that adds a score to each student's grade in each lesson.
  1. Write a query to display students who have not taken the DB course.

In this lab, I used the AdventureWorks2012 database and answered 5 questions:

  1. For the AdventureWorks2012, write a query that returns the general information of the orders being processed, which are between 100000 and 500000, and the place of order is from France or one of the countries in the North American region.
  1. For the AdventureWorks2012, write a query that shows the sales order identification number, customer identification number, order amount(TotalDue), order date, and the name of the region where the order was registered, for each order.
  1. For the AdventureWorks2012, write a query that shows which area had the most orders for each product.
  1. For the AdventureWorks2012, create a table called NAmerica_Sales, which is in accordance with question number 1. Add a column to this table and add a constraint to have only Low, High, or Mid values. Then update this column for each tuple to 'High' when the order cost(TotalDue) is higher than the average total cost (The cost of all orders) on the North American region. Update the column to 'Mid' if the order cost(TotalDue) is equal to the average total cost on the North American region. Finally, update the column to 'Low' when the order cost(TotalDue) is lower than the average total cost on the North American region.
  1. increase all employee salaries for each hour of work by 20%, 15%, 10% or 5%. Then give them a level in accordance with their salaries.

In this lab, I worked with "User" and "Login" in the SQL Server.

  • SQL "Login" is for Authentication:
    • Authentication can decide if we have permission to access the SERVER or not.
    • A "Login" grants the principal entry into the SERVER.
  • SQL server "User" is for Authorization:
    • Authorization decides what are different operations we can do in a DATABASE.
    • A "User" grants a login entry into a single DATABASE.

I answered these questions:

  1. First, create a "Login" in the SQL Server.
  • You can see my answer on line number 1 in the sa_admin.sql file.
  1. Create a role that has the ability to manage the database.
  • You can see my answer on line number 5 in the sa_admin.sql file.
  1. Connect the role to the "Login" created in the first question.
  1. With the "login" created in Question 1, log in to the SQL server and then create a table in the AdventureWorks2012 database, Insert data in this table, and select data from it.
  1. In the AdventureWorks2012 database, create a role called it role2 that has no access to the tables but can only manage permissions.
  1. Grant DataReader permission to role 2.

In this lab, I used the AdventureWorks2012 database and answered 2 questions:

  1. For the AdventureWorks2012, write a query that has the number of orders and the total value of the orders for each Territory along with its Territory area. Show the total number and value of orders for all Territories in one area and at the end of the report for all areas.
  • The output should be the same as the following image:

Screen Shot 2020-05-05 at 3 50 43 PM

  1. For the AdventureWorks2012, write a query that shows the number of orders and the total value of orders for each subcategory of goods along with its category. Show the number and value of orders for all subcategories in one category and at the end of the report for all categories.
  • The output should be the same as the following image:

Screen Shot 2020-05-05 at 4 03 37 PM

In this lab, I used the AdventureWorks2012 database and answered 5 questions:

  1. For the AdventureWorks2012, write a query that shows all the products' names along with the number of sales of each item (Order Qty) in each region as a separate column for each product.
  1. For the AdventureWorks2012, modify the following code, to have the output as shown below:
    select Person.BusinessEntityID, PersonType, Gender
    from Person.Person 
        join HumanResources.Employee
         on (Person.BusinessEntityID = Employee.BusinessEntityID)

Screen Shot 2020-05-18 at 7 33 39 PM

  1. For the AdventureWorks2012, write a query that returns all the products’ names which names are less than 11 characters long and which the 2 left character of name to the end is 'e'. (Like Freewheel)
  1. For the AdventureWorks2012, write a function that gives an 11 character word as input, and if the form of the input is the same as YYYY/MM/DD (Like 2019/09/17) from, it returns 'September 17 2019' otherwise it returns 'Wrong format input'
  1. For the AdventureWorks2012, write a function that gives three inputs for the year, month, and the products’ names, and returns territories that have sold the product at least once on the desired date.

Requirements

Support

Reach out to me at riasiarman@yahoo.com

About

My database lab codes

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TSQL 81.3%
  • PLpgSQL 18.7%
0