Friday, March 9, 2012

How can User add order from only one company at a time

tblUser
--
UserID uniqueidentifier PK (newid)
UserName varchar(MAX)

tblCompany
-
CompanyID uniqueidentifier PK newid()
CompanyName varchar(MAX)

tblUserCart
--
CompanyID uniqueidentifier FK newid()
UserID uniqueidentifier PK
Product varchar(MAX)

Asume we got 3 tables like above. Relation ship is clear: tbluser ->tblUserCart--<tblCompany

What i want is , if user gives an order from a company , sql 2005 will decline the orders from other Companies. Naturally Orders are stored in the tblUserCart table. For example, if user Arnold gives an order of CuttingTool from Company named T3 , Arnold will not be able to give another order from other than T3. I hope im clear about situation.

Happy Coding...

Do you have an application that sits on top of the database so that the tables are populated via the application? If so, that's where I'd perform your logic, rather than trying to build some trigger-based/stored procedure solution in SQL Server.|||I agree.

I would use various SELECT functions within your application to validate weather Arnold could place another order.

So, adding an order for a particular user, query the UserCart table for that user. If an order exists for that user, then flag the app user or only show products from company T3

We could write this as a procedure, put lets put the client back into Client / Server |||So answer is , do it on application. Thanks for answers.

No comments:

Post a Comment