Using the General Hardware Corp. relational database to generate a batch of SQL Server scripts
Verified
Added on Β 2023/04/22
|4
|1054
|212
AI Summary
Contribute Materials
Your contribution can guide someoneβs learning journey. Share your
documents today.
6.Consider the General Hardware Corp. relational database and the data stored in it,as shown in Figure 5.14.create a single SQL Server script (a batch) combining answers to the sections b, d, e, f. Your script should start with the correct USE command followed by a series of queries. Beware that you should take care to not include more info in the output than was specified in those four sections, e.g. there should be no additional. In production environment, such βextrasβ may disclose confidential information or extend the output beyond the portable deviceβs screen. b.Select rows from the CUSTOMER EMPLOYEE relation in which CustomerNumber = 2198.Project Employee Number and Employee Name over that result. d.Select rows from the PRODUCT relation in which Product Number = 21765.Project Unit Price over that result. e.Join the SALESPERSON and CUSTOMER relations using the SalespersonNumber attribute of each as the join fields.Select rows from that result in whichSalesperson Name = Baker.Project Customer Name over that result. f.Join the PRODUCT relation and the SALES relation using the Product Numberattribute of each as the join fields.Select rows in which Product Name = Pliers.Project Salesperson Number and Quantity over that result. Solution: Script: useGeneralHardware_00252034; SELECTEMPNUM,EMPNAMEFROMCUSTOMEREMPLOYEEWHERECUSTNUM=2198; SELECTUNITPRICEFROMPRODUCTWHEREPRODNUM=21765; SELECTCUSTNAMEFROMSALESPERSONINNERJOINCUSTOMERONSALESPERSON.SPNUM= CUSTOMER.SPNUMWHERESPNAME='Baker'; SelectSPNUM,QUANTITYfromPRODUCTINNERJOINSALESonPRODUCT.PRODNUM=SALES.PRODNUM wherePRODNAME='Pliers'; Output:
Secure Best Marks with AI Grader
Need help grading? Try our AI Grader for instant feedback on your assignments.
Task 2 Often, database analysts and designers deal with existing databases and have to make their best guesses about the intent of the original database creators and plan how to adapt them to reflect the business needs of the existing owners. Northwind diagram should be created on the NHCC server, as directed in the beginning of this Unit. Analyze it and, if necessary, for understanding, right-click on table names and Select Top 1000 Rows. Give an example where it would be the best choice when deleting/updating a record belonging to one of the Northwind tables. Total three examples: (a) No Action; (b) Set Default OR Set Null; (c) Cascade. Present each example in the format: β’ the table name on βoneβ side or relation; β’ the foreign key involved; β’ business justification of using this particular rule. As is often the case, there may be different possible answers. I will read your justifications attentively. For example, Restrict Rule justification may be needed if we want to keep records not just for an ongoing operation but also for a possible audit of the past transactions.
Solution: Northwind Diagram: Categories CategoryIDint CategoryNamenvarchar(15) Descriptionntext Pictureimage Column NameData TypeAllow Nulls Customers CustomerIDnchar(5) CompanyNamenvarchar(40) ContactNamenvarchar(30) ContactTitlenvarchar(30) Addressnvarchar(60) Citynvarchar(15) Regionnvarchar(15) PostalCodenvarchar(10) Countrynvarchar(15) Phonenvarchar(24) Faxnvarchar(24) Column NameData TypeAllow Nulls Employees EmployeeIDint LastNamenvarchar(20) FirstNamenvarchar(10) Titlenvarchar(30) TitleOfCourtesynvarchar(25) BirthDatedatetime HireDatedatetime Addressnvarchar(60) Citynvarchar(15) Regionnvarchar(15) PostalCodenvarchar(10) Countrynvarchar(15) HomePhonenvarchar(24) Extensionnvarchar(4) Photoimage Notesntext ReportsToint PhotoPathnvarchar(255) Column NameData TypeAllow Nulls Order Details OrderIDint ProductIDint UnitPricemoney Quantitysmallint Discountreal Column NameData TypeAllow Nulls Orders OrderIDint CustomerIDnchar(5) EmployeeIDint OrderDatedatetime RequiredDatedatetime ShippedDatedatetime ShipViaint Freightmoney ShipNamenvarchar(40) ShipAddressnvarchar(60) ShipCitynvarchar(15) ShipRegionnvarchar(15) ShipPostalCodenvarchar(10) ShipCountrynvarchar(15) Column NameData TypeAllow Nulls Products ProductIDint ProductNamenvarchar(40) SupplierIDint CategoryIDint QuantityPerUnitnvarchar(20) UnitPricemoney UnitsInStocksmallint UnitsOnOrdersmallint ReorderLevelsmallint Discontinuedbit Column NameData TypeAllow Nulls Shippers ShipperIDint CompanyNamenvarchar(40) Phonenvarchar(24) Column NameData TypeAllow Nulls Suppliers SupplierIDint CompanyNamenvarchar(40) ContactNamenvarchar(30) ContactTitlenvarchar(30) Addressnvarchar(60) Citynvarchar(15) Regionnvarchar(15) PostalCodenvarchar(10) Countrynvarchar(15) Phonenvarchar(24) Faxnvarchar(24) HomePagentext Column NameData TypeAllow Nulls Examples: (a)No Action Table Name:Category Foreign Key Involved:CategoryID Business Justification: When a particular category is to be deleted but it has product which belongs to the category, the category should not be deleted and hence no action is performed. (b)Set Default OR Set Null; Table Name: Shipper Foreign Key Involved:ShipVia in Order Table Business Justification:
In the stream of the business many shippers come and some leave in between. It is not important to maintain these details in order too. Therefore, it can be updated to NULL. So, when a shipper is deleted the corresponding ShipVia attribute is set to NULL. (c)Cascade: Table Name:Order Foreign Key Involved:OrderID Business Justification: When particular Order is deleted all the OrderDetails of the particular OrderID is deleted. This is done because sometimes a customer may cancel the order in such case all the order details of them can be removed from the table and need not be maintained in the database.