You are here: Re: Newbie with SQL Server Trigger « MsSQL Server « IT news, forums, messages
Re: Newbie with SQL Server Trigger

Posted by Erland Sommarskog on 02/20/07 23:16

(ricardo.sobral.santos@googlemail.com) writes:
> 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)

It's not clear why you have different data type, and least of all
why you make things difficult to throw in an IDENTITY.

> 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)

This you cannot do. Keep in mind that a trigger fires once per
statement, so there can be multiple rows. But there is no need
for variables. Just say:

INSERT (...)
SELECT ... FROM inserted

> VALUES
> (@Email, nvarchar(50),
> ,@Password, nvarchar(50),
> ,@Username, nvarchar(50),
> ,@UserID, varchar(16),)

I don't really know that this is supposed to be, but maybe you mean

convert(nvarchar(50), Email)


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

 

Navigation:

[Reply to this 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

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