Reply to Newbie with SQL Server Trigger

Your name:

Reply:


Posted by ricardo.sobral.santos on 02/20/07 05:59

Hello,

I am using ASP.NET 2.0 Membership services and to save some time I am
not extending the Membership. I realized that I can create a table
named "Users" and with a Trigger fill it with a replica of the
aspnet_membership table (UserID, Email, Password) and then continue to
use the other tables that I had already created before which are
linked to Users table.

Example of tables: Users(Suposed Copy of aspnet_membership),
Challenge, ChallengeRatings, aspnet_membership(contains all the data
from the registered users).

My "Users" table contains the same identical data. The biggest problem
is that the UserID in "aspnet_membership" table is a uniqueidentifier
so I cannot link it directly to the "Users" since it has different
data types. ([UniqueIdentifier] VS [Int] with identity)

I was wondering if there is a way for me to create a trigger, and
everytime that a user is created in aspnet_membership to insert it
also in User with a different primary key such as varchar(16) to avoid
data type colisions.

A wrong written rough idea:

GO
CREATE TRIGGER InsertIntoUser
ON aspnet_Membership
AFTER INSERT
AS
DECLARE
@userID varchar(16),
@Email nvarchar(50),
@Password nvarchar(50),
@Username nvarchar(50)

SET @userID = (Inserted userID in aspnet_membership)
@Email = (Inserted email in aspnet_membership)
@Password = (Inserted Password in aspnet_membership)
@Username = (Inserted Username in aspnet_membership)
BEGIN
INSERT INTO [WikedCompetitions].[dbo].[Users]
([Email]
,[Password]
,[Username]
,[UserID])
VALUES
(@Email, nvarchar(50),
,@Password, nvarchar(50),
,@Username, nvarchar(50),
,@UserID, varchar(16),)
WHERE Users.UserID = inserted.UserID
END

Now just really have to make it right since I am quite a newbie at
Triggers!

Thank you in advance for any replies,

Ricardo

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация