473,396 Members | 1,734 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,396 software developers and data experts.

Column restruction

Hi,

Is there a way of ensuring that a mySQL table column will contain one
and only one true (with the remainder being false).

I want to set a value of true (or '1') to a row and be assured that
the remaining rows are false (or '0'). Or is this something that has
to be done php side?

Thanks
Jul 20 '05 #1
3 1240
Gooseman wrote:
Is there a way of ensuring that a mySQL table column will contain one
and only one true (with the remainder being false).

I want to set a value of true (or '1') to a row and be assured that
the remaining rows are false (or '0'). Or is this something that has
to be done php side?


With two queries that would be simple:

update tablename set value='0';
update tablename set value='1' where id='something';
Jul 20 '05 #2
Aggro wrote:
Gooseman wrote:
Is there a way of ensuring that a mySQL table column will contain one and only one true (with the remainder being false).

I want to set a value of true (or ’1’) to a row and be assured that the remaining rows are false (or ’0’). Or is this something that has to be done php side?


With two queries that would be simple:

update tablename set value=’0’;
update tablename set value=’1’ where id=’something’;

Do this if the tables are already populated. Otherwise, if you are
just building the tables, set a default value for the particular
field.

--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/mySQL-Column...ict124862.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=416074
Jul 20 '05 #3
steve wrote:
Aggro wrote:
> Gooseman wrote:
> > I want to set a value of true (or ’1’) to a row and be assured
> > that the remaining rows are false (or ’0’). Or is this something
> > that has to be done php side?

> update tablename set value=’0’;
> update tablename set value=’1’ where id=’something’;

Do this if the tables are already populated. Otherwise, if you are
just building the tables, set a default value for the particular
field.


The solutions above _permit_ but do not _enforce_ the condition that
Gooseman described.

We have only a few constraints in MySQL, including primary key, unique
index, and foreign key. MySQL does not seem to support an arbitrary
expression as a table-level constraints as some RDBMS implementations
do. CHECK constraints in CREATE TABLE statements are parsed but not
enforced.

Another way to enforce this is to write triggers on UPDATE and INSERT
operations that validate the value and either abort the operation or
else alter the value that is being input. But according to the web page:
http://dev.mysql.com/doc/mysql/en/AN..._Triggers.html
Triggers are scheduled to be implemented in MySQL 5.1 (and as we all
know, priorities can change).

So I think you're going to have to do the enforcement in your
application code.

Regards,
Bill K.
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: nimdez | last post by:
Hi, I am working on an existing code base in which a lot of data displayed to the user is formatted in tables. Most tables are printed row-by-row using printf() with "%s" print conversion...
4
by: perspolis | last post by:
I have 3 columns in my datatabel name Total,unit,Price. I use a column expression in my project..and in this expression i multiplied two column... for example ...
6
by: Robert Schuldenfrei | last post by:
Dear NG, After being away from C# programming for a spell, I am trying my hand at what should be a simple task. I have been hitting my head against the wall this morning. I have a simple order...
19
by: Owen T. Soroke | last post by:
Using VB.NET I have a ListView with several columns. Two columns contain integer values, while the remaining contain string values. I am confused as to how I would provide functionality to...
6
by: Aaron Smith | last post by:
Ok. I have a dataset that has multiple tables in it. In one of the child tables, I have a column that I added to the DataSet (Not in the DataSource). This column does not need to be stored in the...
2
by: ricky | last post by:
Hello, If anyone could help me with this I would highly appreciate it. I've tried everything and nothing works. What I am trying to do is so damn basic and it's just frustrating that it seems...
3
by: TPhelps | last post by:
I have a sample of an unbound (autogeneratecolumns is true) sortable/pagable datagrid that works. I want to change one of the columns to a hyperlink. The examples I find use a bound column. I...
4
by: Steph. | last post by:
I have a List view displaying data in Detail mode with several columns. How I can get the column index the user clicked on ? (when user click on an item inside the ListView, not on a column...
4
by: Peter Gibbs | last post by:
I need some help with this problem. I'm using Access 2002 with XP. My problem is with a 2-column listbox. My VBA code puts text data into the listbox. The problem is that the text data...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.