473,394 Members | 1,852 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

database constraints, quick ways???

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
4 2222
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Ruby Tuesdays | last post by:
Perhaps you database guru able to suggest what would be a good choice for opensource database platform to use to develop projects. At the moment the project is small/medium, but it will grow in...
0
by: Rajesh Kapur | last post by:
We use InnoDB tables and foreign key constraints extensively. The mysqldump backs up the database tables in alphabetical order with foreign key constraints defined in the create statement of each...
3
by: serge | last post by:
I have all the scrips to create a database. I have a few questions: 1- I am creating a batch file that it will call many lines like: db2 -td@ -f filename.sql -z output.txt The order i am using...
3
by: cql90 | last post by:
Hi all PRO, I don't know how to create the MSAccess database in the runtime with C#, Are there any body know how to do this? I am pretty sure that all of you know how to do it, except me :( ....
4
by: Martin Pritchard | last post by:
Hi, I'm working on a project that historically contains around 40 enums. In the database various fields refer to the int values of these enums, but of course ref integrity is not enofrced and...
6
by: Sally Sally | last post by:
I wanted to dump the contents of one table to another (with a different name) within the same database. I am looking at pg_restore and it doesn't seem to have the option of specifying the name of...
3
by: teedilo | last post by:
Our MS SQL (SQL Server 2000) DBA has database privileges locked down pretty tightly. We end users/developers do not have administrator privileges for most databases. That arrangement has worked...
6
by: sarada7 | last post by:
How to check if DB Constraints are enabled in a database?
10
by: Phil Latio | last post by:
I am inserting data into user table which contains 5 fields, sounds simple enough normally but 2 of the fields are designated as UNIQUE. If someone does enter a value which already exists, how do I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.