Showing posts with label user. Show all posts
Showing posts with label user. Show all posts

Tuesday, March 27, 2012

Duplicate records on database

hi all,

How do i avoid duplicate records on my database? i have 4 textboxes that collect user information and this information is saved in the database. when a user fills the textboxes and clicks the submit button, i want to check through the database if the exact records exist in the database before the data is saved. if the user is registered on the database, he wont be allowed to login. how can i acheive this?

i thought of using the comparevalidator but i'm not sure how to proceed.

thanks

You can check for the existence of the record before you insert to avoid duplicates.

IF NOT EXISTS ( SELECT * FROM YourTable WHER <Condition>)

BEGIN

INSERT INTO ...

END

|||

1declare @.login_namevarchar(50)2declare @.messagevarchar(100)34set @.login_name ='CS4Ever'56IFEXISTS (SELECT 1FROM RegisterationTableWHERE LoginName = @.login_name)7BEING-- user already registered89set @.message ='Sorry ' + @.login_name +', you are already registered!'1011END-- user already registered12ELSE-- user not registered yet13BEGIN-- user not registered yet1415insert into RegisterationTable (LoginName)values (@.login_name)1617if(@.@.rowcount = 1)18begin-- user added sucessfully19set @.message = @.login_name +', you have been registered sucessfully.'20end-- user added sucessfully21else-- faild in adding user22set @.message ='Registereation filed', please contact registeration office!23begin-- faild in adding user24end-- faild in adding user2526END-- user not registered yet
 
Good luck.
sql

Monday, March 26, 2012

Duplicate Process ID

I have a stored procedure that uses cursers. This stored
procedure executed by a user from MTS server. At times,
when I refresh the 'Current Activity' and look
into 'Process Info' window in EM, I see two process ID (ID
54) for the same stored proc. Shouldn't the ID's be unique
and assigned only 1 for this SP ? Would this be a SP
issue ?
It is on Win 2K SQL 2K SP2 (With latest patch before SP3)
Thanks.
That means, the query inside your sp is doing parallel processing. SQL
Server can make use of more than one processor, if available - based on the
query.
More information on parallelism can be found in SQL Sever 2000 Books Online.
You can restrict parallelism by using the MAXDOP hint.
HTH,
Vyas, MVP (SQL Server)
http://vyaskn.tripod.com/
Is .NET important for a database professional?
http://vyaskn.tripod.com/poll.htm
"Dan" <anonymous@.discussions.microsoft.com> wrote in message
news:73ba01c47647$1c37efc0$a401280a@.phx.gbl...
I have a stored procedure that uses cursers. This stored
procedure executed by a user from MTS server. At times,
when I refresh the 'Current Activity' and look
into 'Process Info' window in EM, I see two process ID (ID
54) for the same stored proc. Shouldn't the ID's be unique
and assigned only 1 for this SP ? Would this be a SP
issue ?
It is on Win 2K SQL 2K SP2 (With latest patch before SP3)
Thanks.
|||Thanks.

>--Original Message--
>That means, the query inside your sp is doing parallel
processing. SQL
>Server can make use of more than one processor, if
available - based on the
>query.
>More information on parallelism can be found in SQL Sever
2000 Books Online.
>You can restrict parallelism by using the MAXDOP hint.
>--
>HTH,
>Vyas, MVP (SQL Server)
>http://vyaskn.tripod.com/
>Is .NET important for a database professional?
>http://vyaskn.tripod.com/poll.htm
>
>"Dan" <anonymous@.discussions.microsoft.com> wrote in
message
>news:73ba01c47647$1c37efc0$a401280a@.phx.gbl...
>I have a stored procedure that uses cursers. This stored
>procedure executed by a user from MTS server. At times,
>when I refresh the 'Current Activity' and look
>into 'Process Info' window in EM, I see two process ID (ID
>54) for the same stored proc. Shouldn't the ID's be unique
>and assigned only 1 for this SP ? Would this be a SP
>issue ?
>It is on Win 2K SQL 2K SP2 (With latest patch before SP3)
>Thanks.
>
>.
>

Duplicate Process ID

I have a stored procedure that uses cursers. This stored
procedure executed by a user from MTS server. At times,
when I refresh the 'Current Activity' and look
into 'Process Info' window in EM, I see two process ID (ID
54) for the same stored proc. Shouldn't the ID's be unique
and assigned only 1 for this SP ' Would this be a SP
issue ?
It is on Win 2K SQL 2K SP2 (With latest patch before SP3)
Thanks.That means, the query inside your sp is doing parallel processing. SQL
Server can make use of more than one processor, if available - based on the
query.
More information on parallelism can be found in SQL Sever 2000 Books Online.
You can restrict parallelism by using the MAXDOP hint.
--
HTH,
Vyas, MVP (SQL Server)
http://vyaskn.tripod.com/
Is .NET important for a database professional?
http://vyaskn.tripod.com/poll.htm
"Dan" <anonymous@.discussions.microsoft.com> wrote in message
news:73ba01c47647$1c37efc0$a401280a@.phx.gbl...
I have a stored procedure that uses cursers. This stored
procedure executed by a user from MTS server. At times,
when I refresh the 'Current Activity' and look
into 'Process Info' window in EM, I see two process ID (ID
54) for the same stored proc. Shouldn't the ID's be unique
and assigned only 1 for this SP ' Would this be a SP
issue ?
It is on Win 2K SQL 2K SP2 (With latest patch before SP3)
Thanks.|||Thanks.

>--Original Message--
>That means, the query inside your sp is doing parallel
processing. SQL
>Server can make use of more than one processor, if
available - based on the
>query.
>More information on parallelism can be found in SQL Sever
2000 Books Online.
>You can restrict parallelism by using the MAXDOP hint.
>--
>HTH,
>Vyas, MVP (SQL Server)
>http://vyaskn.tripod.com/
>Is .NET important for a database professional?
>http://vyaskn.tripod.com/poll.htm
>
>"Dan" <anonymous@.discussions.microsoft.com> wrote in
message
>news:73ba01c47647$1c37efc0$a401280a@.phx.gbl...
>I have a stored procedure that uses cursers. This stored
>procedure executed by a user from MTS server. At times,
>when I refresh the 'Current Activity' and look
>into 'Process Info' window in EM, I see two process ID (ID
>54) for the same stored proc. Shouldn't the ID's be unique
>and assigned only 1 for this SP ' Would this be a SP
>issue ?
>It is on Win 2K SQL 2K SP2 (With latest patch before SP3)
>Thanks.
>
>.
>

Duplicate Process ID

I have a stored procedure that uses cursers. This stored
procedure executed by a user from MTS server. At times,
when I refresh the 'Current Activity' and look
into 'Process Info' window in EM, I see two process ID (ID
54) for the same stored proc. Shouldn't the ID's be unique
and assigned only 1 for this SP ' Would this be a SP
issue ?
It is on Win 2K SQL 2K SP2 (With latest patch before SP3)
Thanks.That means, the query inside your sp is doing parallel processing. SQL
Server can make use of more than one processor, if available - based on the
query.
More information on parallelism can be found in SQL Sever 2000 Books Online.
You can restrict parallelism by using the MAXDOP hint.
--
HTH,
Vyas, MVP (SQL Server)
http://vyaskn.tripod.com/
Is .NET important for a database professional?
http://vyaskn.tripod.com/poll.htm
"Dan" <anonymous@.discussions.microsoft.com> wrote in message
news:73ba01c47647$1c37efc0$a401280a@.phx.gbl...
I have a stored procedure that uses cursers. This stored
procedure executed by a user from MTS server. At times,
when I refresh the 'Current Activity' and look
into 'Process Info' window in EM, I see two process ID (ID
54) for the same stored proc. Shouldn't the ID's be unique
and assigned only 1 for this SP ' Would this be a SP
issue ?
It is on Win 2K SQL 2K SP2 (With latest patch before SP3)
Thanks.|||Thanks.
>--Original Message--
>That means, the query inside your sp is doing parallel
processing. SQL
>Server can make use of more than one processor, if
available - based on the
>query.
>More information on parallelism can be found in SQL Sever
2000 Books Online.
>You can restrict parallelism by using the MAXDOP hint.
>--
>HTH,
>Vyas, MVP (SQL Server)
>http://vyaskn.tripod.com/
>Is .NET important for a database professional?
>http://vyaskn.tripod.com/poll.htm
>
>"Dan" <anonymous@.discussions.microsoft.com> wrote in
message
>news:73ba01c47647$1c37efc0$a401280a@.phx.gbl...
>I have a stored procedure that uses cursers. This stored
>procedure executed by a user from MTS server. At times,
>when I refresh the 'Current Activity' and look
>into 'Process Info' window in EM, I see two process ID (ID
>54) for the same stored proc. Shouldn't the ID's be unique
>and assigned only 1 for this SP ' Would this be a SP
>issue ?
>It is on Win 2K SQL 2K SP2 (With latest patch before SP3)
>Thanks.
>
>.
>

Thursday, March 22, 2012

Duplicate an existig SQL user login account

How does one create a copy of an existing SQL login account. I have a
database that has a single login with everything setup. I just want to be
able to copy the existing account to a new user so I can set a different
password.
Thanks!You might be able to get what you want by "Generating SQL Script" from
the right-click context menu on the database you want to add the user
to. Place the checkmarks on the first tab to create all types of
objects, uncheck the options to create the CREATE and DROP statements on
the second tab, and go to the 3rd tab and check "Script object-level
permissions".
When you build the script, it should include commands that grant the
permissions to the current account that holds the permissions. You will
have to manually pick through the script commands to find the
appropriate ones and change the name of the user to replace the old
user's username with the new one to build an entirely new script.
While not the answer you're looking for, I think you should consider
creating one or more roles configured to grant permissions that match
the account that is configured properly now, then create the new account
and add the both user accounts to the role you created.
Good luck,
Tony Sebion
"John Williams" <JohnWilliams@.discussions.microsoft.com> wrote in
message news:5EA1D83E-15E9-44B9-9707-C4AAB5C9CDB6@.microsoft.com:

> How does one create a copy of an existing SQL login account. I have a
> database that has a single login with everything setup. I just want to be
> able to copy the existing account to a new user so I can set a different
> password.
> Thanks!sql

Monday, March 19, 2012

Dumb trigger question

Table with last UpdatedBy Column and LastUpdatedOn Column.
Want to create Insert and Update Triggers that would automatically write
Logged in User Name and System Date Time to each field.
I Think User is SUSER_SNAME function and System date Is GETDATE() but can't
figure out how to write these two to row from within a trigger in table.
Any help greatly appreciated.
BobYou can use the inserted psuedo-table to identify the updated rows. One
method:
CREATE TRIGGER TR__Update_MyTable
ON MyTable FOR UPDATE
AS
UPDATE MyTable
SET UpdatedBy = SUSER_SNAME(),
LastUpdatedOn = GETDATE()
WHERE EXISTS
(
SELECT *
FROM inserted
WHERE inserted.PK = MyTable.PK
)
Hope this helps.
Dan Guzman
SQL Server MVP
"Bob" <bdufour@.sgiims.com> wrote in message
news:uwISI5NzFHA.3188@.TK2MSFTNGP14.phx.gbl...
> Table with last UpdatedBy Column and LastUpdatedOn Column.
> Want to create Insert and Update Triggers that would automatically write
> Logged in User Name and System Date Time to each field.
> I Think User is SUSER_SNAME function and System date Is GETDATE() but
> can't figure out how to write these two to row from within a trigger in
> table.
> Any help greatly appreciated.
> Bob
>|||Use an INSTEAD OF trigger. The deleted pseudotable is a copy of any
existing rows that are about to be updated, the inserted pseudotable
contains the new values. The deleted pseudotable will be empty if the
operation was INSERT. The inserted pseudotable will be empty if the
operation was DELETE. Both pseudotables will have the same number of rows
if the operation was UPDATE. The reason you should use an INSTEAD OF
trigger is that it allows you to change values before it hits the database.
The only problem with them is that the cascade kludge won't coexist, which
in my opinion is a good thing.
In an INSTEAD OF UPDATE trigger, you simply issue an update statement:
UPDATE tableName
SET column1 = inserted.column1,
column2 = inserted.column2,
..,
UpdatedBy = SUSER_SNAME(),
LastUpdatedOn = GETDATE()
FROM inserted
WHERE primaryKeyColumn = inserted.primaryKeyColumn
The only time this is a problem is if you're using natural keys. If that's
the case, then you need to test for multiple rows
put code similar to this at the top of the trigger
--Don't put anything before this!!!
DECLARE @._ROWCOUNT INT SET @._ROWCOUNT = @.@.ROWCOUNT
IF @._ROWCOUNT = 0 RETURN
IF @._ROWCOUNT > 1 AND (UPDATE(primaryKeyColumn1) OR
UPDATE(primaryKeyColumn2))
BEGIN
ROLLBACK TRANSACTION
RAISERROR('ATTEMPT TO UPDATE Primary Key using set-based operation', 16, 0)
RETURN
END
"Bob" <bdufour@.sgiims.com> wrote in message
news:uwISI5NzFHA.3188@.TK2MSFTNGP14.phx.gbl...
> Table with last UpdatedBy Column and LastUpdatedOn Column.
> Want to create Insert and Update Triggers that would automatically write
> Logged in User Name and System Date Time to each field.
> I Think User is SUSER_SNAME function and System date Is GETDATE() but
> can't figure out how to write these two to row from within a trigger in
> table.
> Any help greatly appreciated.
> Bob
>|||Thank you both very much
Bob
"Bob" <bdufour@.sgiims.com> wrote in message
news:uwISI5NzFHA.3188@.TK2MSFTNGP14.phx.gbl...
> Table with last UpdatedBy Column and LastUpdatedOn Column.
> Want to create Insert and Update Triggers that would automatically write
> Logged in User Name and System Date Time to each field.
> I Think User is SUSER_SNAME function and System date Is GETDATE() but
> can't figure out how to write these two to row from within a trigger in
> table.
> Any help greatly appreciated.
> Bob
>