Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old July 9th, 2007, 04:38 AM
Registered User
Join Date: May 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to prashant_telkar Send a message via MSN to prashant_telkar Send a message via Yahoo to prashant_telkar
Default problem with trigger in registration form

i m creating a registration form, i hav two tables,one for all user information and another for storing only username and password.i hav written trigger to fetch username and password from user information table to my 2nd table say login table.now comes problem....as i hav applied primary key on username in user information table and passed reference in login table but because of primary key records are arranged in ascendind order so tigger is fetching the last row instead of the current inserted record.

plz help me out with code and explanation with example.....asap

Old July 9th, 2007, 05:17 PM
Friend of Wrox
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts

Why do you need a trigger to fetch username/password? Why can't you just use a simple query? If you're inserting username and password and want to get the identity of that record, you can get it in the insert statement:

SET NOCOUNT ON; INSERT INTO [table] (col1, col2, col3) VALUES (var1, var2, var3);SELECT ThePrimaryKey = @@IDENTITY; SET NOCOUNT OFF;

Old July 9th, 2007, 06:52 PM
Friend of Wrox
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts

Oh, no, no, no... using @@IDENTITY, especially when triggers are involved, is a form of "Death by SQL" and will return the incorrect ID if a trigger does an insert (never take the chance). Use Scope_Identity() instead.

--Jeff Moden

Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in registration form prashant_telkar ASP.NET 1.x and 2.0 Application Design 5 July 11th, 2007 01:09 AM
Registration Form Help invisible bunny king Classic ASP Databases 7 February 5th, 2007 05:30 PM
server registration problem pitter SQL Server 2005 2 December 30th, 2005 11:22 AM
server registration problem pitter SQL Server 2000 1 December 27th, 2005 04:53 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.