Click here to Skip to main content
15,895,656 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Ensure that,
 quantity of a product is always greater than 0
 default date for a sale is the system date

What I have tried:

Product (prodId, prodName, qty, unitPrice, ROL, supplier)
Customer (custId, custName, address, phone, loyalityPoints)
Staff (staffId , staffName, phone)
Sales (prodId, custId, staffId, salesDate)
Supplier (supId, contactName, phone, address)

but I cannot implement the sql code.
Posted
Updated 8-Sep-21 22:09pm

OriginalGriff is right to point you in the direction of CONSTRAINTS
Here is more detail.

SQL
-- to add a default
ALTER TABLE Sales 
  ADD CONSTRAINT DF_Sales_SalesDate DEFAULT GETDATE() FOR SalesDate

-- to remove the default
ALTER TABLE Sales
  DROP CONSTRAINT IF EXISTS DF_Sales_SalesDate
 
Share this answer
 
 
Share this answer
 
Comments
Jörgen Andersson 9-Sep-21 5:02am    
Or SYSDATETIME() or SYSUTCDATETIME() if you want to be a bit more up to date. :)
OriginalGriff 9-Sep-21 5:19am    
I live in Wales, we're lucky to be up to date with the 80's ... :D
Jörgen Andersson 9-Sep-21 5:24am    
Still on Emmerdale and Eastenders then?
Or does it have to be Pobol y Cwm?
OriginalGriff 9-Sep-21 6:09am    
:shudder:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900