Link to home
Start Free TrialLog in
Avatar of JDay2
JDay2

asked on

Need a stored procedure or trigger for populating removing information

Have following user table

aspnet_users table
UserID
UserName

When I create the user I need this information to auto-populate another table and the same if I delete the user

users table
UserID = aspnet table UserID
Name = aspnet table Username
UserName = aspnet table Username
Avatar of JDay2
JDay2

ASKER

How do I accomplish this with a stored procedure or tigger?
SOLUTION
Avatar of Anthony Perkins
Anthony Perkins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JDay2

ASKER

Okay I have a few  questions and I'm going to break them into steps

I had to remove the Action column in your code because don't have that column.

USE []
GO
/****** Object:  Trigger [dbo].[trg_insertUsers]    Script Date: 3/24/2015 10:08:50 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TRIGGER [dbo].[trg_insertUsers] ON [dbo].[aspnet_Users] AFTER INSERT
AS

INSERT dbo.Users(UserID, UserName)
SELECT  UserID, UserName
FROM	Inserted

Open in new window


this works for inserting but I need to insert into a name column in the dbo.users table based of Username is this possible?

How do I implement the delete piece based of the UserID?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Fair enough.  I would have been more inclined to use a single TRIGGER, but whatever works for you.
Avatar of JDay2

ASKER

The initial post gave me the direction but I didn't have an action column in my table.
The post help understand the concept to formulate the following triggers.