-2

I´m trying to create a MSSQL tabel where after a UserRegistation (create user wizard) the UserID from "aspnet_Users (dbo)" will be copied into this new tabel. Can anyone tell me how to do this?

Thanks

r5d
  • 579
  • 5
  • 24
RMU
  • 37
  • 3
  • 8

1 Answers1

0

If you want an automated system that responds on specific actions, a TRIGGER is what you're most likely looking for.

In your case, it sounds as if you want to respond to INSERTs happening on the dbo.aspnet_Users table. The code would be something similar to this (pseudo-code, not tested):

CREATE TRIGGER trgNewUser ON dbo.aspnet_Users 
AFTER INSERT 
AS
INSERT INTO myTable (userID)
SELECT userID FROM INSERTED

INSERTED is a special logical table that essentially has the same structure as the table the trigger is created on, and it will contain the latest row INSERTed into the table. Thus, you can use that to capture newly added records, and have the trigger take appropriate actions.

More info on Triggers:

Use the inserted and deleted Tables on Technet

CREATE TRIGGER (Transact-SQL)

SchmitzIT
  • 9,227
  • 9
  • 65
  • 92