Showing posts with label orders. Show all posts
Showing posts with label orders. Show all posts

Monday, March 19, 2012

How to detect a login under windows security?

I have a SQL Server 2000 on an intranet with windows security. A stored
procedure is called every time users add orders into table ORDERS.
How can I detect the login name and domain for the user that adds a new
order? What would the lines of code look like in the stored procedure?
Regards
Tore G.Hi
SELECT SUSER_SNAME()
Regards
--
Mike Epprecht, Microsoft SQL Server MVP
Zurich, Switzerland
IM: mike@.epprecht.net
MVP Program: http://www.microsoft.com/mvp
Blog: http://www.msmvps.com/epprecht/
"nospam@.tgylnospam.no" <nospamtgylnospamno@.discussions.microsoft.com> wrote
in message news:E126A1B3-179D-405A-8E57-55BE76F669CB@.microsoft.com...
>I have a SQL Server 2000 on an intranet with windows security. A stored
> procedure is called every time users add orders into table ORDERS.
> How can I detect the login name and domain for the user that adds a new
> order? What would the lines of code look like in the stored procedure?
> Regards
> Tore G.

Wednesday, March 7, 2012

How to delete from two tables at once

I have 2 tables "Orders" and "OrderProducts"

In my application, there are moments when I clean up these tables.

There is a query that looks for some flag in the "Orders" table, and deletes the records.

But there are related (PK-FK) records in the "OrderProducts" table.

How can I delete also these records in the same query?

I suppose you use SQL 2005 and Sql Server management Studio. If so, then you must specify INSERT and UPDATE specification during the PK-FK constraint creation, and set the delete rule as 'cascade'. If you do so, then if you delete an 'order', then all the corresponding 'orderProducts' will also be deleted.

|||

Either delete all the records from the child table first or use the "ON DELETE CASCADE" method.