Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6868731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:28:13+00:00 2026-05-27T03:28:13+00:00

I have a assignment due so any help would help a lot thank you!

  • 0

I have a assignment due so any help would help a lot thank you!

Not sure if I did it right any help would be great thank you!

Create a trigger so that no sales transaction can be initially entered or modified that is larger than the credit limit. If the sales transaction is over the credit limit, roll back the transaction.

My Code

Create Trigger salesTransaction on Customers
For insert, update
as
--Get Credit limit
Declare @@Creditlimit money
select @@Creditlimit = CreditLimt from inserted i
Declare @@amount money
select @@amount = (p.Price * s.qtyOrdered) from inserted i
inner join Orders o
on i.CustomerNo = o.CustomerNo
inner join SalesDetail s
on s.OrderNo = o.OrderNo
inner join Products p
on (p.ManufactureID + p.ProductID) = (s.ManufactureID + s.ProductID)
where (i.CustomerNo = o.CustomerNo and o.CustomerNo = s.OrderNo and s.ManufactureID = p.ManufactureID and s.ProductID = p.ProductID)
if(@@amount > @@Creditlimit)
Begin
rollback transaction
End

My tables

Create Table Customers
(
CustomerNo char(4) 
Constraint ck_CustomerNoHas4positionsWithNumbers
Check(CustomerNo like'[0-9],[0-9],[0-9],[0-9]'),
Company varchar(50) not null,
CustomerRep char(3),
CreditLimt money default(20000.00),
PRIMARY KEY(CustomerNo)
)
Alter Table Customers
Add constraint fk_customerrep
FOREIGN KEY (CustomerRep) 
REFERENCES Salesreps(EmployeeNo)

Create Table Orders
(
OrderNo int,
OrderDate Date not null,
CustomerNo char(4) not null,
SalesRep char(3) not null
PRIMARY KEY(OrderNo)
)
Alter Table Orders
Add constraint fk_customerno
FOREIGN KEY (CustomerNo)
REFERENCES Customers(CustomerNo),
constraint fk_salesrep
FOREIGN KEY (SalesRep)
REFERENCES Salesreps(EmployeeNo)
Create Table SalesDetail
(
SaleDetailID int,
ManufactureID char(3) Constraint ck_ManufactureIDFromSaleDetails check(ManufactureID like'[a-z],[a-z],[a-z]') not null,
ProductID char(5) Constraint ck_ProductIDSalesDetail check(ProductID like'[0-9],[0-9],[a-z],[a-z],[a-z]') not null,
OrderNo int,
qtyOrdered int
PRIMARY KEY(SaleDetailID)
)

Alter Table SalesDetail
add FOREIGN KEY (OrderNo)
REFERENCES Orders(OrderNo)

Alter Table SalesDetail 
Add constraint fk_SalesDetails_Mid_Pid
FOREIGN KEY (ManufactureID, ProductID) 
REFERENCES Products(ManufactureID, ProductID) 

Create Table Products
(
ManufactureID char(3) 
Constraint ck_ManufactureIDifItHasLettersOnly check(ManufactureID like'[a-z],[a-z],[a-z]'),
ProductID char(5) 
Constraint ck_ProductIDhasTwoLettersAndThreeNumbers check(ProductID like'[a-z],[a-z],[0-9],[0-9],[0-9]'),
Description varchar(50) not null,
Price money not null,
QtyOnHand int not null,
PRIMARY KEY(ManufactureID, ProductID)
)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T03:28:13+00:00Added an answer on May 27, 2026 at 3:28 am

    Several things:

    • WHY is the trigger on Customer ?? You don’t want to check these conditions when a new customer is inserted (or updated) – but rather when a new Order is inserted – no??

    • Your code doesn’t take into account the fact that the trigger will be called once per statement and that this one statement can very well insert (or update) multiple orders at once – therefore, the Inserted pseudo table can (and will!) contain multiple entries, and your code doesn’t work with multiple entries….

    So my take would be:

    • Put the trigger on the Orders table
    • Make it so that it can handle multiple rows in Inserted
    • I count the number of rows I find where the order total exceeds the customer’s CreditLimit – if that’s greater than zero (at least one order exceeds that limit), I roll back the transaction.

    Here’s the trigger code:

    CREATE TRIGGER salesTransaction ON dbo.Orders
    FOR INSERT, UPDATE
    AS
      --Get Credit limit
      DECLARE @Count INT
    
      SELECT @COUNT = COUNT(*)
      FROM Inserted i
      INNER JOIN dbo.Orders o ON i.CustomerNo = o.CustomerNo
      INNER JOIN SalesDetail s ON s.OrderNo = o.OrderNo
      INNER JOIN Products p ON p.ManufactureID = s.ManufactureID AND m.Product = s.ProductID
      INNER JOIN dbo.Customer c ON o.CustomerNo = c.CustomerNo
      WHERE (p.Price * s.qtyOrdered) > c.CreditLimit
    
      IF (@Count > 0)
         ROLLBACK TRANSACTION
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an assignment to create a GUI using MATLAB GUIDE and am having
I have a C assignment. It is a lot longer than the code shown
I have Assignment due in which i'm stuck on a question. Add a Sales
I have this assignment due that requires the usage of FLTK. The code is
For my Operating Systems class I have an assignment due that is built onto
Hmm not sure if the title of this makes any sense. I'm creating a
I have an assignment due in my intro database class - and I'm stumped
Is it possible to have assignment in a condition? For ex. if (a=some_func()): #
I have an assignment in a language-independent class, and part of it is using
I have an assignment about fftw and I was trying to write a small

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.