database constraints, quick ways???

  • Thread starter Thread starter ozgur develioglu
  • Start date Start date
O

ozgur develioglu

hi everyone,

I've a USER table which contains USERNAME column. I try to keep
usernames unique. When I'm adding I new user, I frist go to database and
check if that username already exists and if no I add that user. As you see
I went to database two times. In order to do this can I set the column
unique at SQL Server 2000 and at the program side check the errors.
I'm dealing with a ASP.NET application and I need quick user adding
operation.

thanks in advance.
Ozgur Develioglu
 
Hi,

A better way is to create a SP that first check if the user exist, if so it
does not insert it and return an error code, otherwise it insert it and
return the new ID of the record. with this you only do a call to the DB.

Hope this help,
 
Ignacio and Ozgur,

Why not just place a constraint on that column which forces it to be
unique? This would seem to be the easiest way.

Hope this helps.
 
Ignatio,

I was implying that the constraint be placed on the DB itself, not the
data set.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Ignacio Machin said:
Hi Nicholas,

The thing is that if he is working on a multiuser environment ( asp.net
app ) unless that you keep the dataset in application context you cannot
assure the uniqueness of the row being inserted, having the dataset in app.
you need to take care of concurrency , so that's is easier to go to the DB
to persist the changes.

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

in message news:Ol06jj%[email protected]...
Ignacio and Ozgur,

Why not just place a constraint on that column which forces it to be
unique? This would seem to be the easiest way.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Ignacio Machin said:
Hi,

A better way is to create a SP that first check if the user exist, if
so
it
does not insert it and return an error code, otherwise it insert it and
return the new ID of the record. with this you only do a call to the DB.

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

hi everyone,

I've a USER table which contains USERNAME column. I try to keep
usernames unique. When I'm adding I new user, I frist go to database and
check if that username already exists and if no I add that user. As you
see
I went to database two times. In order to do this can I set the column
unique at SQL Server 2000 and at the program side check the errors.
I'm dealing with a ASP.NET application and I need quick user adding
operation.

thanks in advance.
Ozgur Develioglu
 
Haa,

Ok, yes, a constrain in the DB is a must.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

Nicholas Paldino said:
Ignatio,

I was implying that the constraint be placed on the DB itself, not the
data set.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Ignacio Machin said:
Hi Nicholas,

The thing is that if he is working on a multiuser environment ( asp.net
app ) unless that you keep the dataset in application context you cannot
assure the uniqueness of the row being inserted, having the dataset in app.
you need to take care of concurrency , so that's is easier to go to the DB
to persist the changes.

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

in message news:Ol06jj%[email protected]...
Ignacio and Ozgur,

Why not just place a constraint on that column which forces it to be
unique? This would seem to be the easiest way.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

"Ignacio Machin" <ignacio.machin AT dot.state.fl.us> wrote in message
Hi,

A better way is to create a SP that first check if the user exist,
if
so
it
does not insert it and return an error code, otherwise it insert it and
return the new ID of the record. with this you only do a call to the DB.

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

hi everyone,

I've a USER table which contains USERNAME column. I try to keep
usernames unique. When I'm adding I new user, I frist go to
database
and
check if that username already exists and if no I add that user.
As
you
see
I went to database two times. In order to do this can I set the column
unique at SQL Server 2000 and at the program side check the errors.
I'm dealing with a ASP.NET application and I need quick user adding
operation.

thanks in advance.
Ozgur Develioglu
 
Back
Top