By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,713 Members | 1,326 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,713 IT Pros & Developers. It's quick & easy.

database constraints, quick ways???

P: n/a
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
Nov 15 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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

"ozgur develioglu" <oz*************@yahoo.com> wrote in message
news:eE**************@TK2MSFTNGP10.phx.gbl...
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

Nov 15 '05 #2

P: n/a
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]
- ni**************@exisconsulting.com

"Ignacio Machin" <ignacio.machin AT dot.state.fl.us> wrote in message
news:ue****************@TK2MSFTNGP09.phx.gbl...
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

"ozgur develioglu" <oz*************@yahoo.com> wrote in message
news:eE**************@TK2MSFTNGP10.phx.gbl...
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


Nov 15 '05 #3

P: n/a
Ignatio,

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

--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Ignacio Machin" <ignacio.machin AT dot.state.fl.us> wrote in message
news:%2*****************@tk2msftngp13.phx.gbl...
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

"Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com> wrote in message news:Ol****************@tk2msftngp13.phx.gbl...
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]
- ni**************@exisconsulting.com

"Ignacio Machin" <ignacio.machin AT dot.state.fl.us> wrote in message
news:ue****************@TK2MSFTNGP09.phx.gbl...
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

"ozgur develioglu" <oz*************@yahoo.com> wrote in message
news:eE**************@TK2MSFTNGP10.phx.gbl...
> 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
>
>



Nov 15 '05 #4

P: n/a
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 [.NET/C# MVP]" <ni**************@exisconsulting.com> wrote
in message news:eo**************@tk2msftngp13.phx.gbl...
Ignatio,

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

--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Ignacio Machin" <ignacio.machin AT dot.state.fl.us> wrote in message
news:%2*****************@tk2msftngp13.phx.gbl...
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

"Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com>

wrote
in message news:Ol****************@tk2msftngp13.phx.gbl...
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]
- ni**************@exisconsulting.com

"Ignacio Machin" <ignacio.machin AT dot.state.fl.us> wrote in message
news:ue****************@TK2MSFTNGP09.phx.gbl...
> 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
>
> "ozgur develioglu" <oz*************@yahoo.com> wrote in message
> news:eE**************@TK2MSFTNGP10.phx.gbl...
> > 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
> >
> >
>
>



Nov 15 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.