Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Crima
Starting Member
17 Posts |
Posted - 2012-11-14 : 20:16:56
|
This is my homework can someone look it over? any and all help would be great thanks !: )--2. Based on the design above, answer the following questions. All the answers have to be in--the form of a .sql script.--a. Create a new database named Membership.--b. Write the CREATE TABLE statements needed to implement the design from 1 in--the Membership database. Include reference constraints. Define IndividualID and--GroupID with the IDENTITY keyword. Decide which columns should allow null--values, if any, and explain your decisions.--A.CREATE DATABASE Members--B.CREATE TABLE Individuals(Individual_Id int,LastName varchar(255),FirstName varchar(255),Address varchar(255),Phone varchar(255))CREATE TABLE GGroup(Group_ID int,GroupName varchar(255))--3.USE [AP]GOALTER TABLE [dbo].[Invoices] WITH NOCHECK ADD CONSTRAINT [AllowNonNullPaymentDate] CHECK (([PaymentDate] IS NOT NULL AND [PaymentTotal]>(0)))GOALTER TABLE [dbo].[Invoices] CHECK CONSTRAINT [AllowNonNullPaymentDate]GOALTER TABLE [dbo].[Invoices] WITH NOCHECK ADD CONSTRAINT [AllowNullPaymentDate] CHECK (([PaymentDate] IS NULL AND [PaymentTotal]=(0)))GOALTER TABLE [dbo].[Invoices] CHECK CONSTRAINT [AllowNullPaymentDate]GOALTER TABLE --4.Write a CREATE VIEW statement that defines a view named InvoiceBasic that returns--three columns: VendorName, InvoiceNumber, and InvoiceTotal. Then, write a SELECT--statement that returns all of the columns in the view, sorted by VendorName, where the--first letter of the vendor name is N, O, or P. CREATE VIEW InvoiceBasic ASSELECT VendorName, InvoiceNumber, InvoiceTotalFROM Invoices JOIN Vendors ON Invoices.InvoiceID = Vendors.VendorIDALTER VIEW InvoicebasicASSELECT*FROM Invoices JOIN Vendors ON Invoices.InvoiceID = Vendors.VendorIDWHERE VendorName ' --5.CREATE View Top10PaidInvoices asSelect Top 10 VendorName, Max(InvoiceDate) as LastInvoice,Sum(InvoiceTotal) as SumOfInvoicesFrom Vendors Join InvoicesOn Vendors.VendorID = Invoices.VendorIDWhere (InvoiceTotal - PaymentTotal - CreditTotal) > 0Group By VendorNameOrder By SumOfInvoices DESCCREATE VIEW TOP10PaidInvoices AS SELECT TOP 10 Vendors.VendorName, Invoices.LastInvoice AS InvoiceDate, Invoices.SumOfInvoice AS InvoiceTotal, FROM Invoices INNER JOIN Vendors ON Invoices.InvoiceID = Vendors.VendorID ORDER BY SumOfInvoices ASC ------------------------------------------------------------------------------------ --EXTRA CREDIT----------------------------------------------------------------------------------------1.Modify your design from problem 1 to keep track of the role served by each individual in--each group. Each individual can only serve one role in each group. Each group has a--unique set of roles that members can fulfill. Create additional tables and columns, if--necessary. Explain your design decisions.--2.Write an ALTER TABLE statement that adds two new check constraints to the Invoices--table of the AP database. The first should allow (1) PaymentDate to be null only if--PaymentTotal is zero and (2) PaymentDate to be not null only if PaymentTotal is greater--than zero. The second constraint should prevent the sum of PaymentTotal and--CreditTotal from being greater than InvoiceTotal.ALTER TABLE Invoices WITH CHECK ADD check ( (PaymentTotal = 0 AND PaymentDate is NULL) OR (PaymentTotal > 0 AND PaymentDate is NOT NULL) ) goALTER TABLE Invoices WITH CHECKADD CHECK ( (PaymentTotal + CreditTotal) <= InvoiceTotal ) go--3.Create an updatable view named VendorAddress that returns the VendorID, both address--columns, and the city, state, and zip code columns for each vendor. Then, write a--SELECT query to examine the result set where VendorID=4. Next, write an UPDATE--statement that changes the address so that the suite number (Ste 260) is stored in--VendorAddress2 rather than in VendorAddress1. To verify the change, rerun your--SELECT query.CREATE VIEW VendorAddressreturn VendorID, VendorAddress1, VendorAddress2, VendorState, VendorZip, VendorCitySELECT VendorID = 4UPDATE --4. Write a SELECT statement that selects all of the columns from the catalog view that--returns information about foreign keys. How many foreign keys are defined in the AP--database?SELECT * CatalogViewWHERE |
|
ahmeds08
Aged Yak Warrior
737 Posts |
Posted - 2012-11-15 : 01:16:43
|
what have tried till now?post it and someone can help if you are stuck anywhere. |
|
|
Crima
Starting Member
17 Posts |
Posted - 2012-11-15 : 15:08:36
|
I have fixed and completed everything but the last question (4)I'm not sure how to select catalog view.A witty student |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
|
|
|
|
|
|