<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
    <channel>
        <title>MySQL Forums - Constraints</title>
        <description>Forum for Constraints</description>
        <link>http://forums.mysql.com/list.php?136</link>
        <lastBuildDate>Wed, 22 May 2013 07:00:34 +0000</lastBuildDate>
        <generator>Phorum 5.2.19</generator>
        <item>
            <guid>http://forums.mysql.com/read.php?136,587042,587042#msg-587042</guid>
            <title>Why am I not able to name index differently from foreign constraint name (no replies)</title>
            <link>http://forums.mysql.com/read.php?136,587042,587042#msg-587042</link>
            <description><![CDATA[ Hi<br />
<br />
my environment is as follow:<br />
<br />
<pre class="bbcode">
mysql&gt; show variables like '%version%';
+-------------------------+------------------------------+
| Variable_name           | Value                        |
+-------------------------+------------------------------+
| innodb_version          | 1.1.8                        |
| protocol_version        | 10                           |
| slave_type_conversions  |                              |
| version                 | 5.5.27                       |
| version_comment         | MySQL Community Server (GPL) |
| version_compile_machine | x86                          |
| version_compile_os      | Win32                        |
+-------------------------+------------------------------+
7 rows in set (0.00 sec)</pre>
<br />
<pre class="bbcode">

create table if not exists test1(
test1_id int,
test1_string varchar(10),
constraint pk_test1 primary key (test1_id) using hash comment 'primary key index for test1'
);

create table if not exists test1_child(
test1_child_id int,
test1_id int not null,
test1_child_string varchar(10),
constraint fk_test1_child_test_id foreign key fk_test1_child_test_id (test1_id) references test1 (test1_id)
);</pre>
<br />
next I decided to have different index name and foreign key constraint_name on test1_child, so I did the following:<br />
<br />
from <a href="http://dev.mysql.com/doc/refman/5.5/en/alter-table.html"  rel="nofollow">http://dev.mysql.com/doc/refman/5.5/en/alter-table.html</a><br />
<br />
<pre class="bbcode">

alter table test1_child drop foreign key fk_test1_child_test_id;

alter table test1_child drop index fk_test1_child_test_id;


alter table test1_child add constraint fk_test1_child_test_id foreign key fk_test1_child_test_id_index (test1_id) references test1(test1_id);</pre>
<br />
however results does not show what I expect<br />
<br />
<pre class="bbcode">


mysql&gt; show index from test1_child;
+-------------+------------+------------------------+--------------+------------
-+-----------+-------------+----------+--------+------+------------+---------+--
-------------+
| Table       | Non_unique | Key_name               | Seq_in_index | Column_name
 | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | I
ndex_comment |
+-------------+------------+------------------------+--------------+------------
-+-----------+-------------+----------+--------+------+------------+---------+--
-------------+
| test1_child |          1 | fk_test1_child_test_id |            1 | test1_id
 | A         |           0 |     NULL | NULL   |      | BTREE      |         |
             |
+-------------+------------+------------------------+--------------+------------
-+-----------+-------------+----------+--------+------+------------+---------+--</pre>
<br />
from the referential_constraints<br />
<br />
<pre class="bbcode">
mysql&gt; select CONSTRAINT_SCHEMA, CONSTRAINT_NAME, UNIQUE_CONSTRAINT_SCHEMA, UNIQ
UE_CONSTRAINT_NAME, REFERENCED_TABLE_NAME from INFORMATION_SCHEMA.REFERENTIAL_CO
NSTRAINTS where table_name='test1_child';
+-------------------+------------------------+--------------------------+-------
-----------------+-----------------------+
| CONSTRAINT_SCHEMA | CONSTRAINT_NAME        | UNIQUE_CONSTRAINT_SCHEMA | UNIQUE
_CONSTRAINT_NAME | REFERENCED_TABLE_NAME |
+-------------------+------------------------+--------------------------+-------
-----------------+-----------------------+
| certify           | fk_test1_child_test_id | certify                  | PRIMAR
Y                | test1                 |
+-------------------+------------------------+--------------------------+-------
-----------------+-----------------------+
1 row in set (0.00 sec)</pre>
<br />
as you will have observe the foreign key constraint name is the same as the index_name, could anyone explain?<br />
<br />
thanks a lot!]]></description>
            <dc:creator>Chun Hung Leng</dc:creator>
            <category>Constraints</category>
            <pubDate>Wed, 22 May 2013 06:39:25 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?136,587038,587038#msg-587038</guid>
            <title>Why are I not able to name my primary key constraint (no replies)</title>
            <link>http://forums.mysql.com/read.php?136,587038,587038#msg-587038</link>
            <description><![CDATA[ Hi,<br />
<br />
my environment is as follow:<br />
<br />
<pre class="bbcode">
mysql&gt; show variables where variable_name like '%version%';
+-------------------------+------------------------------+
| Variable_name           | Value                        |
+-------------------------+------------------------------+
| innodb_version          | 1.1.8                        |
| protocol_version        | 10                           |
| slave_type_conversions  |                              |
| version                 | 5.5.27                       |
| version_comment         | MySQL Community Server (GPL) |
| version_compile_machine | x86                          |
| version_compile_os      | Win32                        |
+-------------------------+------------------------------+
7 rows in set (0.00 sec)</pre>
<br />
this is my create table statement<br />
<br />
<pre class="bbcode">
create table if not exists test1(
test1_id int,
test1_string varchar(10),
constraint pk_test1 primary key (test1_id) using hash comment 'primary key index for test1'
);</pre>
<br />
this is what i retrieved from show create table<br />
<br />
<pre class="bbcode">

mysql&gt; show create table test1;
+-------+-----------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------+
| Table | Create Table

                                                                          |
+-------+-----------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------+
| test1 | CREATE TABLE `test1` (
  `test1_id` int(11) NOT NULL DEFAULT '0',
  `test1_string` varchar(10) DEFAULT NULL,
  PRIMARY KEY (`test1_id`) USING HASH COMMENT 'primary key index for test1'
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |</pre>
<br />
as you realize the name of the primary key constraint is not effective.<br />
<br />
<pre class="bbcode">
mysql&gt; select CONSTRAINT_SCHEMA, CONSTRAINT_NAME, TABLE_SCHEMA, CONSTRAINT_TYPE
from INFORMATION_SCHEMA.TABLE_CONSTRAINTS where TABLE_NAME='test1';
+-------------------+-----------------+--------------+-----------------+
| CONSTRAINT_SCHEMA | CONSTRAINT_NAME | TABLE_SCHEMA | CONSTRAINT_TYPE |
+-------------------+-----------------+--------------+-----------------+
| certify           | PRIMARY         | certify      | PRIMARY KEY     |
+-------------------+-----------------+--------------+-----------------+
1 row in set (0.02 sec)
<pre class="bbcode">

why is this so? from <a href="http://dev.mysql.com/doc/refman/5.5/en/create-table.html"  rel="nofollow">http://dev.mysql.com/doc/refman/5.5/en/create-table.html</a>, I doubt that there's anything wrong with my syntax.

<pre class="bbcode">

mysql&gt; show index from test1;
+-------+------------+----------+--------------+-------------+-----------+------
-------+----------+--------+------+------------+---------+----------------------
-------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardi
nality | Sub_part | Packed | Null | Index_type | Comment | Index_comment
       |
+-------+------------+----------+--------------+-------------+-----------+------
-------+----------+--------+------+------------+---------+----------------------
-------+
| test1 |          0 | PRIMARY  |            1 | test1_id    | A         |
     0 |     NULL | NULL   |      | BTREE      |         | primary key index for
 test1 |
+-------+------------+----------+--------------+-------------+-----------+------
-------+----------+--------+------+------------+---------+----------------------
-------+
1 row in set (0.00 sec)</pre>
<br />
if you take a close look, you will realize that index type is BTREE and not HASH as desired.</pre></pre>]]></description>
            <dc:creator>Chun Hung Leng</dc:creator>
            <category>Constraints</category>
            <pubDate>Wed, 22 May 2013 04:45:39 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?136,582914,582914#msg-582914</guid>
            <title>ocl constraint {Xor} check (2 replies)</title>
            <link>http://forums.mysql.com/read.php?136,582914,582914#msg-582914</link>
            <description><![CDATA[ hello everyone :)<br />
<br />
during the preparation of my relational model, I'm stuck at the translation of a type constraint {XOR}.<br />
<br />
here's an example: I have a file that is equivalent credit by an applicant (a user) and it is also validated by a validator (another user) but there is an exclusion constraint the applicant may not be the validator to the same folder.<br />
<br />
how I can translate it at my table<br />
<br />
Dossier_Equi (num_dosier, # applicant # validator ......)<br />
Does anyone have the proposal???<br />
<br />
Thank you in advance]]></description>
            <dc:creator>feres feres</dc:creator>
            <category>Constraints</category>
            <pubDate>Tue, 02 Apr 2013 15:26:42 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?136,581304,581304#msg-581304</guid>
            <title>Error: 1557 SQLSTATE: 23000 (ER_FOREIGN_DUPLICATE_KEY)  How to fix this issue? (1 reply)</title>
            <link>http://forums.mysql.com/read.php?136,581304,581304#msg-581304</link>
            <description><![CDATA[ Dear MySQL professionals,<br />
<br />
my db gives me the mentioned error message when I try to update a table.<br />
I have no idea how to find out the table row that is actually leading to the &quot;duplicate key&quot; problem.<br />
<br />
Can you give me a hint how to start?<br />
<br />
Maybe the problem is caused when I fill the database with SET_FOREIGN_KEY_CHECKS=0 entering invalid data?<br />
<br />
Cheers,<br />
<br />
Sebastian]]></description>
            <dc:creator>Sebastian Schwaiger</dc:creator>
            <category>Constraints</category>
            <pubDate>Thu, 14 Mar 2013 23:16:43 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?136,573286,573286#msg-573286</guid>
            <title>Multiply column values (1 reply)</title>
            <link>http://forums.mysql.com/read.php?136,573286,573286#msg-573286</link>
            <description><![CDATA[ Hi guys<br />
<br />
I am trying to create a table like below<br />
<br />
mysql&gt; CREATE TABLE orders<br />
    -&gt; ( Salesman_code int NOT NULL,<br />
    -&gt; Salesman_name char(20) NOT NULL,<br />
    -&gt; Order_date date NOT NULL,<br />
    -&gt; City char(20),<br />
    -&gt; Rate int,<br />
    -&gt; Quantity int,<br />
    -&gt; Amount AS Rate * Quantity);<br />
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS Rate * Quantity)' at line 8<br />
mysql&gt;<br />
<br />
I want to assign the multiplied value of Rate &amp; Quantity to Amount. I have seen a similar usage in another forum but in my case, its giving an error! I searched for &quot;AS/AS command&quot; at <a href="http://dev.mysql.com/doc/refman/5.6/en/sql-syntax.html"  rel="nofollow">http://dev.mysql.com/doc/refman/5.6/en/sql-syntax.html</a> but no hits! Am I looking at the right location for general sql syntax? Is it possible to get a detailed error output? The material that I am using to practice SQL queries contains lot of example programs but when I execute them, most of them end up with errors like above. Can someone recommend me a material to practice SQL queries on MySQL RDBMS? Any help would be much appreciated! <br />
<br />
Regards,<br />
Anish]]></description>
            <dc:creator>Anish Philip</dc:creator>
            <category>Constraints</category>
            <pubDate>Mon, 10 Dec 2012 07:34:45 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?136,572271,572271#msg-572271</guid>
            <title>Check constraint not working (6 replies)</title>
            <link>http://forums.mysql.com/read.php?136,572271,572271#msg-572271</link>
            <description><![CDATA[ Hi guys<br />
<br />
This is my first post in this forum. I am not sure if this is right place to post this question. I have a question regarding my check constraint. I created a table &quot;item&quot; with a CHECK constraint on columns ROL and QOH to check if ROL&lt;QOH. It seems that the constraint is not working as the table is accepting values for QOH less than ROL! Please tell me if there is any syntax error in the below commands!<br />
<br />
mysql&gt; CREATE TABLE items (<br />
    -&gt; icode char(5) NOT NULL,<br />
    -&gt; descp char(20) NOT NULL,<br />
    -&gt; ROL integer,<br />
    -&gt; QOH integer,<br />
    -&gt; PRIMARY KEY (icode),<br />
    -&gt; CHECK (ROL&lt;QOH));<br />
Query OK, 0 rows affected (0.10 sec)<br />
<br />
mysql&gt; DESCRIBE items;<br />
+-------+----------+------+-----+---------+-------+<br />
| Field | Type     | Null | Key | Default | Extra |<br />
+-------+----------+------+-----+---------+-------+<br />
| icode | char(5)  | NO   | PRI | NULL    |       |<br />
| descp | char(20) | NO   |     | NULL    |       |<br />
| ROL   | int(11)  | YES  |     | NULL    |       |<br />
| QOH   | int(11)  | YES  |     | NULL    |       |<br />
+-------+----------+------+-----+---------+-------+<br />
4 rows in set (0.00 sec)<br />
<br />
mysql&gt; INSERT INTO items (icode, descp, ROL, QOH) VALUES ('ABC', 'New employee', 234, 500);<br />
Query OK, 1 row affected (0.36 sec)<br />
<br />
mysql&gt; SELECT * FROM items;<br />
+-------+--------------+------+------+<br />
| icode | descp        | ROL  | QOH  |<br />
+-------+--------------+------+------+<br />
| ABC   | New employee |  234 |  500 |<br />
+-------+--------------+------+------+<br />
1 row in set (0.00 sec)<br />
<br />
mysql&gt; INSERT INTO items (icode, descp, ROL, QOH) VALUES ('DEF', 'New employee', 224, 100);<br />
Query OK, 1 row affected (0.09 sec)<br />
<br />
mysql&gt; SELECT * FROM items;<br />
+-------+--------------+------+------+<br />
| icode | descp        | ROL  | QOH  |<br />
+-------+--------------+------+------+<br />
| ABC   | New employee |  234 |  500 |<br />
| DEF   | New employee |  224 |  100 |<br />
+-------+--------------+------+------+<br />
2 rows in set (0.00 sec)<br />
<br />
mysql&gt;]]></description>
            <dc:creator>Anish Philip</dc:creator>
            <category>Constraints</category>
            <pubDate>Thu, 08 Nov 2012 19:03:28 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?136,570528,570528#msg-570528</guid>
            <title>Cardinality vs. distinct values (1 reply)</title>
            <link>http://forums.mysql.com/read.php?136,570528,570528#msg-570528</link>
            <description><![CDATA[ Dear all,<br />
<br />
Can somebody explain to me the difference between cardinality and distinct(unique) values.<br />
<br />
The reason I ask this is after I run an 'analyze table orders;' the 'show indexes from orders;' gives me a cardinality of 18 on my index created on the column order_id. But, when I run a 'select count(distinct order_id) from orders;' I receive a count of 47 distinct values.<br />
<br />
I find this odd as I thought cardinality was indeed the count of unique values of a column.]]></description>
            <dc:creator>Nathan Aschoff</dc:creator>
            <category>Constraints</category>
            <pubDate>Wed, 31 Oct 2012 09:07:01 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?136,566839,566839#msg-566839</guid>
            <title>mysterious DDL failure for PK (1 reply)</title>
            <link>http://forums.mysql.com/read.php?136,566839,566839#msg-566839</link>
            <description><![CDATA[ i cannot figure out why i am unable to create the PK:<br />
<br />
CREATE TABLE ts_hAccountingUnit<br />
(	<br />
	accUnitID char(6) not null,<br />
	subrgnID char(4) not null,<br />
	accUnitDesc text<br />
);<br />
<br />
ALTER TABLE ts_hAccountingUnit<br />
ADD CONSTRAINT pk_ts_hAccountingUnit<br />
PRIMARY KEY accUnitID;<br />
<br />
***I am able to create a FK***<br />
<br />
ALTER TABLE ts_hAccountingUnit<br />
ADD CONSTRAINT fk1_ts_hAccountingUnit<br />
FOREIGN KEY (subrgnID) REFERENCES ts_hSubregion(subrgnID);<br />
<br />
meanwhile, another PK creation has no problem:<br />
<br />
CREATE TABLE ts_hSubregion<br />
(<br />
	subrgnID char(4) not null,<br />
	rgnID char(2) not null,<br />
	subrgnDesc text<br />
);<br />
ALTER TABLE ts_hSubregion<br />
ADD CONSTRAINT pk_ts_hSubregion<br />
PRIMARY KEY subrgnID;<br />
<br />
although it follows identical syntax]]></description>
            <dc:creator>Foam Pile</dc:creator>
            <category>Constraints</category>
            <pubDate>Fri, 31 Aug 2012 12:04:26 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?136,564231,564231#msg-564231</guid>
            <title>Index Type created not same as mentioned in documentation. (1 reply)</title>
            <link>http://forums.mysql.com/read.php?136,564231,564231#msg-564231</link>
            <description><![CDATA[ Hello,<br />
<br />
We have installed the following cluster version on linux:<br />
<br />
SELECT VERSION();<br />
5.5.19-ndb-7.2.4-gpl<br />
<br />
w.r.t the following link:<br />
<a href="http://dev.mysql.com/doc/refman/5.5/en/create-index.html"  rel="nofollow">http://dev.mysql.com/doc/refman/5.5/en/create-index.html</a><br />
for the section &quot;index_type&quot; :<br />
<br />
I tried out the stuff mentioned for the description of &quot;index_type&quot; &amp; found the following differences:<br />
1) As per the documentation:<br />
<br />
...Where multiple index types are listed, the first one is the default when no index type specifier is given.<br />
<br />
Storage Engine				Permissible Index Types<br />
MyISAM						BTREE<br />
InnoDB						BTREE<br />
MEMORY/HEAP					HASH, BTREE<br />
NDB							HASH, BTREE (see note in text)<br />
<br />
So as per above I created a table &amp; created an index on the table &amp; expected the index type to be &quot;HASH&quot;, but it is actually a &quot;BTREE&quot; index.<br />
<br />
	CREATE TABLE lookup<br />
		(id INT)<br />
		engine=ndb;<br />
<br />
alter table lookup add index idx_simple (id);<br />
[I even tried the CREATE INDEX, without specifying the &quot;USING BTREE&quot; option]<br />
<br />
I refered the index type from TOAD UI, which showed it as &quot;BTREE&quot;. I also refered the information_schema.statistics table <br />
for the index name = &quot;idx_simple&quot;, which showed as &quot;BTREE&quot; under the column &quot;INDEX_TYPE&quot;.<br />
<br />
2) As per the documentation:<br />
Note<br />
For indexes on NDB table columns, the USING option can be specified only for a unique index or primary key.<br />
<br />
But, I was able to create a normal index as mentioned below by using the &quot;USING&quot; clause.<br />
	CREATE INDEX id_index ON lookup (id) USING BTREE;<br />
<br />
3) As per the documentation:<br />
USING HASH prevents the creation of an implicit ordered index; otherwise, creating a unique index or primary key on an NDB table automatically results in the creation of both an ordered index and a hash index, each of which indexes the same set of columns.<br />
<br />
How do I get information on the above two indexes created (in &quot;mysql&quot; or &quot;information_schema&quot; db).<br />
<br />
<br />
Regards,<br />
Sachin Vyas.]]></description>
            <dc:creator>Sachin Vyas</dc:creator>
            <category>Constraints</category>
            <pubDate>Tue, 09 Oct 2012 13:24:30 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?136,544628,544628#msg-544628</guid>
            <title>[solved] ERROR 1170: key length for index on textfield is specified but still this error (1 reply)</title>
            <link>http://forums.mysql.com/read.php?136,544628,544628#msg-544628</link>
            <description><![CDATA[ Hello,<br />
<br />
Ik have the following query:<br />
<br />
CREATE TABLE `test_index_on_type_textfield` (<br />
  `id` smallint(5) unsigned NOT NULL,<br />
  `name` varchar(50) NOT NULL,<br />
  `content` tinytext,<br />
  PRIMARY KEY (`id`),<br />
  INDEX `filter_on_name` (`name`),<br />
  INDEX `filter_on_content` (`content`(1000))<br />
) ENGINE=MyISAM DEFAULT CHARSET=latin1;<br />
<br />
<br />
The query is executed succesfully, the table is created. When I view the stored indexes, the index on column 'content' has the key length 1000.<br />
<br />
But when I try to alter any column, I get the following error: &quot;#1170 BLOB/TEXT column 'content' used in key specification without a key length&quot;.<br />
<br />
What is wrong?]]></description>
            <dc:creator>Sebastiaan Nieuwenhuis</dc:creator>
            <category>Constraints</category>
            <pubDate>Wed, 30 May 2012 07:50:13 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?136,540336,540336#msg-540336</guid>
            <title>duplicate index which has name of foreign key constraint (no replies)</title>
            <link>http://forums.mysql.com/read.php?136,540336,540336#msg-540336</link>
            <description><![CDATA[ I downloaded the Percona Toolkit which contains a program called pt-duplicate-key-checker. This analyzes all indexes in a database and spits out duplicates with a suggestion on how to remove the duplicate index.<br />
<br />
One thing Im noticing over and over again are duplicate Foreign Key indexes when an existing index already existed, usually the primary key. For example:<br />
<br />
CREATE TABLE `	` (<br />
  `ID` bigint(20) NOT NULL,<br />
  `ASSIGNMENT_ID` varchar(255) DEFAULT NULL,<br />
  `TITLE` varchar(255) DEFAULT NULL,<br />
  `TEXT` text,<br />
  `RELEASE_DATE` datetime DEFAULT NULL,<br />
  `RETRACT_DATE` datetime DEFAULT NULL,<br />
  `HIDE` bit(1) DEFAULT NULL,<br />
  PRIMARY KEY (`ID`),<br />
  KEY `FK514CEE15935EEE07` (`ID`),<br />
  CONSTRAINT `FK514CEE15935EEE07` FOREIGN KEY (`ID`) REFERENCES `ASN_SUP_ITEM_T` (`ID`)<br />
) ENGINE=InnoDB DEFAULT CHARSET=utf8<br />
<br />
<br />
mysql&gt; show indexes from ASN_AP_ITEM_T;<br />
+---------------+------------+--------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+<br />
| Table         | Non_unique | Key_name           | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |<br />
+---------------+------------+--------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+<br />
| ASN_AP_ITEM_T |          0 | PRIMARY            |            1 | ID          | A         |           2 |     NULL | NULL   |      | BTREE      |         |<br />
| ASN_AP_ITEM_T |          1 | FK514CEE15935EEE07 |            1 | ID          | A         |           2 |     NULL | NULL   |      | BTREE      |         |<br />
+---------------+------------+--------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+<br />
<br />
<br />
Couldn't we not have the FK514CEE15935EEE07 KEY since ID is already indexed? If so what about this case?<br />
<br />
CREATE TABLE `CM_OFFICIAL_INSTRUCTORS_T` (<br />
  `ENROLLMENT_SET_ID` bigint(20) NOT NULL,<br />
  `INSTRUCTOR_ID` varchar(255) DEFAULT NULL,<br />
  UNIQUE KEY `ENROLLMENT_SET_ID` (`ENROLLMENT_SET_ID`,`INSTRUCTOR_ID`),<br />
  KEY `FK470F8ACCC28CC1AD` (`ENROLLMENT_SET_ID`),<br />
  CONSTRAINT `FK470F8ACCC28CC1AD` FOREIGN KEY (`ENROLLMENT_SET_ID`) REFERENCES `CM_ENROLLMENT_SET_T` (`ENROLLMENT_SET_ID`)<br />
) ENGINE=InnoDB DEFAULT CHARSET=utf8<br />
<br />
In this case it's not primary key, but there is a unique key ENROLLMENT_SET_ID indexing ENROLLMENT_SET_ID and INSTRUCTOR_ID. Since ENROLLMENT_SET_ID is already being indexed isn%u2019t the key FK470F8ACCC28CC1AD a duplicate?<br />
<br />
Is this just the case of MySQL being as default and adding an index when its not needed? Can we remove these which might increase update and insert speeds.]]></description>
            <dc:creator>P P</dc:creator>
            <category>Constraints</category>
            <pubDate>Thu, 24 May 2012 00:00:05 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?136,514636,514636#msg-514636</guid>
            <title>Alter PRIMARY KEY (1 reply)</title>
            <link>http://forums.mysql.com/read.php?136,514636,514636#msg-514636</link>
            <description><![CDATA[ Adding a primary key can be done like this:<br />
ALTER TABLE Persons ADD PRIMARY KEY (id)<br />
<br />
and removing it like this:<br />
ALTER TABLE Persons DROP PRIMARY KEY<br />
<br />
But is it possible to change a PK in a single query? For example like this:<br />
ALTER TABLE Persons DROP PRIMARY KEY, ADD PRIMARY KEY (name)<br />
<br />
Or does ADD PRIMARY KEY override any existing one?]]></description>
            <dc:creator>Auke Middendorp</dc:creator>
            <category>Constraints</category>
            <pubDate>Thu, 10 May 2012 07:28:28 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?136,511681,511681#msg-511681</guid>
            <title>On Functional Dependencies. (no replies)</title>
            <link>http://forums.mysql.com/read.php?136,511681,511681#msg-511681</link>
            <description><![CDATA[ Hello, my first post in this forum (and probably one of the last too).<br />
<br />
First, let me briefly introduce myself; I am a 20 year old Computer Science and Mathematics student and passionate who has been working at his first job in the sector for the past 6 months. The doubt and question I am going to ask has been inside my head since the moment I studied the formal relational database paradigm and at the same time the implementation of SQL for it.<br />
<br />
I know this is not a forum for this kind of questions. This is a forum about MySQL, not about the SQL standard (and as far as I have been able to read, functional dependencies are not even a part of the SQL standard); and this subforum is about constraints within MySQL, not about functional dependencies, but it is what is most similar to functional dependencies, I guess.<br />
<br />
Now onto the topic itself. I have always wondered, as I said, why in hell does SQL not offer the possibility to define functional dependencies and use them for all the different things they could be used?<br />
<br />
As far as I see it, you could analyse it like this.<br />
<br />
Advantages of having functional dependencies:<br />
<br />
* Conceptual.<br />
- Would allow for more clearly defined meanings and constraints of databases.<br />
<br />
* Restrictional.<br />
- Same as foreign keys allow you to make sure that the database data is consistent within the meaning of your universe, functional dependencies would further allow for this. It would be harder to &quot;fuck up&quot; with the data.<br />
<br />
* Operational.<br />
- Auto-normalization of the database would be doable, as there are well thought algorithms for doing this knowing the functional dependencies. In the cases where the amount of data is very high and normalization makes database treatment too slow, you could simply skip auto-normalization; or possibly add a more complex algorithm with parameters setting up &quot;how much normalization&quot; you wish to put on your database. Overall, having the possibility of auto-normalizing would never be bad and would for sure be good in certain cases (it would not be unused, for small databases at least it would be highly recommendable).<br />
<br />
* Search and index efficiency.<br />
- This is probably by long the most important advantage. Imagine a database table where you have a column named &quot;Type&quot; and a column named &quot;Subtype&quot;. It is not far-fetched to think (and imagine in this particular case it is like that) that you have the functional dependency Subtype -&gt; Type. That is, subtypes are actually sub - types of the types, you can't have the same subtype for two different types. Without functional dependencies, the database has no information about the relationship between these 2 columns. Now, you could make 2 indexes, one for Type and one for Subtype; or you could make a compound index of (Type, Subtype). Now imagine the functional dependencies are more complex, and you have yet another third column Class, with the functional dependency Subtype -&gt; Class; and no relationship between Type and Class.<br />
<br />
The result is that you can make 3 simple indexes, 2 compound-indexes or just leave one of the columns un-indexed.<br />
<br />
Now, if you had functional dependencies, you could exclusively define the index on Subtype and still use it partially for searchs or joins on the Type or Class columns. Imagine you had Subtype indexed and you wanted to join the table with antoher table through the Type column. You could create a temporary table with the Subtype and Type of each register of your table ordered by subtype (this would be simply extending the index by adding the Type column, order 1.000.000); then proceed to do the linear search through Type on that table, and once you found a row with a matching Type, you know that all the rows with the same Subtype have therefore the same Type and can bulk-join them as your table is ordered by Subtype. Then simply continue to linearly look for more matching Types.<br />
<br />
In the opposite case. B -&gt; A, C -&gt; A. You could have the index only in A; and the efficiency gain wouldn't be that big, but you could still, to search by B, do a linear search on B until you found an equivalence. Therefore, you know that all other ocurrences of that value b will have a specific value a on the A column (the one that matched). Therefore, for that row of the &lt;&lt;other&gt;&gt; column you can restrict the search to the subset which has a on the A column, which you can separate because A is indexed, and later on remove the row from the &lt;&lt;other&gt;&gt; table and continue the linear join. The gain here is significantly lower and probably deprecatable, but in the first case it isn't.<br />
<br />
<br />
<br />
<br />
Disadvantages of functional dependencies:<br />
<br />
- They are very easy to define and as defined over columns and no data needed to be &quot;maintained&quot; when adding/removing rows (it is a column constraint, as the way its defined); it wouldn't take much space to keep so it isn't a disadvantage on that sense.<br />
<br />
- They can make operations slower when adding new rows, but since typically you will have an index on the left attribute of the dependency (A in A-&gt;B), it will not be that slow. You could even force this index the same way as an index is forced on a foreign key. In any case, this can be controlled by simply not overkilling functional dependencies and LETTING THE DATABASE DESIGNER THINK IF IT IS WORTH USING FUNCTIONAL DEPENDENCIES.<br />
<br />
- You have to program the algorithms??? I don't think lazyness is a disadvantage if there are actual advantages to it.<br />
<br />
<br />
<br />
I know that all of these things are well-known (for those that know them well) and etc... but I wanted to explain them to avoid discussing with other people afterwards about what I have already thought. Overall, I just don't understand the reasoning for simply not adding functional dependencies to SQL.<br />
<br />
Thanks in advance for reading and for your comments.]]></description>
            <dc:creator>Juan Casanova</dc:creator>
            <category>Constraints</category>
            <pubDate>Wed, 25 Jan 2012 16:26:18 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?136,437405,437405#msg-437405</guid>
            <title>Error 1062 duplicate entry (no replies)</title>
            <link>http://forums.mysql.com/read.php?136,437405,437405#msg-437405</link>
            <description><![CDATA[ i am getting following error in mysql slave in replication machine.<br />
<br />
Last_Errno: 1062<br />
                 Last_Error: Error 'Duplicate entry '39f88d2b:132af843b99:-68c5' for key 1' on query.<br />
<br />
<br />
can any one please provide me solution.<br />
<br />
thanks in advance]]></description>
            <dc:creator>zahid quadri</dc:creator>
            <category>Constraints</category>
            <pubDate>Thu, 29 Sep 2011 11:55:54 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?136,434264,434264#msg-434264</guid>
            <title>A Database Error Occurred (no replies)</title>
            <link>http://forums.mysql.com/read.php?136,434264,434264#msg-434264</link>
            <description><![CDATA[ I'm getting error message as below when to view comments or read more at my blog area. Anyone can assist?<br />
<br />
A Database Error Occurred<br />
<br />
Error Number: 1064<br />
<br />
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY RAND() LIMIT 0, 5' at line 7<br />
<br />
SELECT * FROM jem_content_articles WHERE (jem_content_articles.content_tags LIKE '%Blog%'AND content_type = '1' AND date_published &lt;=1316076275 AND (category_id = '1' OR category_id &gt; '6') AND jem_content_articles.status = '1' ORDER BY RAND() LIMIT 0, 5<br />
<br />
MySQL Detail:<br />
    Server: Localhost via UNIX socket<br />
    Server version: 5.0.92-community<br />
    Protocol version: 10<br />
    User: myroshaz@localhost<br />
    MySQL charset: UTF-8 Unicode (utf8)<br />
PHPmyAdmin Version information: 3.4.3.2]]></description>
            <dc:creator>azamazim md noh</dc:creator>
            <category>Constraints</category>
            <pubDate>Thu, 15 Sep 2011 08:49:35 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?136,432351,432351#msg-432351</guid>
            <title>check constraint for fix value in a column (4 replies)</title>
            <link>http://forums.mysql.com/read.php?136,432351,432351#msg-432351</link>
            <description><![CDATA[ hello,<br />
can any one help me .<br />
i need a constraint that should allow only 10 digit to insert into table not 11 and not 9 also. only fix 10 digit.<br />
if any one know please reply me on urgent basis.<br />
<br />
regards<br />
zahid]]></description>
            <dc:creator>zahid quadri</dc:creator>
            <category>Constraints</category>
            <pubDate>Fri, 02 Sep 2011 12:43:19 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?136,430845,430845#msg-430845</guid>
            <title>Where clause for calculated column (no replies)</title>
            <link>http://forums.mysql.com/read.php?136,430845,430845#msg-430845</link>
            <description><![CDATA[ I have a Select statement that includes in the column list:<br />
       datediff(now(), date_added) as Waiting<br />
I wanted to use &quot;Waiting&quot; in the where clause, but got a syntax error.<br />
I ended up using the phrase &quot;datediff(now(), date_added)&quot; in the select statement and it took an unnecessarily long to read all 7 rows in the database.<br />
<br />
I suppose I can work around this restraint by creating a view with &quot;Waiting&quot; defined inside it. Would this work, or is there some undocumented restraint about using that column in the where clause of the view?]]></description>
            <dc:creator>Howard Cary Morris</dc:creator>
            <category>Constraints</category>
            <pubDate>Tue, 16 Aug 2011 04:32:51 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?136,427276,427276#msg-427276</guid>
            <title>Multiple column foreign key (no replies)</title>
            <link>http://forums.mysql.com/read.php?136,427276,427276#msg-427276</link>
            <description><![CDATA[ I have two table named 'customers' and 'accounts' with following create definitions:<br />
<br />
delimiter $$<br />
<br />
CREATE TABLE `customers` (<br />
  `CID` int(10) unsigned NOT NULL,<br />
  `First_Name` varchar(30) NOT NULL,<br />
  `Last_Name` varchar(30) default NULL,<br />
  `Father_Name` varchar(45) default NULL,<br />
  `Address_Res` varchar(100) default NULL,<br />
  `Phone` varchar(60) default NULL,<br />
  `Mobile` varchar(60) default NULL,<br />
  `Comment` varchar(200) default NULL,<br />
  `Register_Date` datetime NOT NULL,<br />
  PRIMARY KEY  (`CID`)<br />
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='Table to store Customer informatios'$$<br />
<br />
delimiter $$<br />
<br />
CREATE TABLE `accounts` (<br />
  `CID` int(10) unsigned NOT NULL,<br />
  `ACN` int(10) unsigned NOT NULL,<br />
  `Loan_Amount` int(10) unsigned NOT NULL,<br />
  `Interest_Rate` decimal(10,0) unsigned NOT NULL,<br />
  `Opening_Date` date NOT NULL,<br />
  `Closing_Date` date NOT NULL,<br />
  `Comment` varchar(200) default NULL,<br />
  `DB_Save_Date` datetime NOT NULL,<br />
  KEY `INDEX_Accounts_ACN` (`ACN`),<br />
  KEY `FK_Accounts` (`CID`),<br />
  CONSTRAINT `FK_Accounts` FOREIGN KEY (`CID`) REFERENCES `customers` (`CID`) ON DELETE NO ACTION ON UPDATE NO ACTION<br />
) ENGINE=InnoDB DEFAULT CHARSET=latin1$$<br />
<br />
========================<br />
Now I want to create another table 'Mortgages' with following definition<br />
<br />
CREATE  TABLE `bankpage_`.`Mortgages` (<br />
<br />
  `CID` INT UNSIGNED NOT NULL ,<br />
<br />
  `ACN` INT UNSIGNED NOT NULL ,<br />
<br />
  `Type` VARCHAR(45) NOT NULL ,<br />
<br />
  `Weight` DECIMAL UNSIGNED NOT NULL ,<br />
<br />
  `Mortgage_Date` DATE NOT NULL ,<br />
<br />
  `Release_Date` DATE NOT NULL ,<br />
<br />
  `IsSeized` TINYINT(1)  NOT NULL ,<br />
<br />
  `Comments` VARCHAR(45) NULL ,<br />
<br />
  INDEX `FK_Mortgages` (`CID` ASC, `ACN` ASC) ,<br />
<br />
  CONSTRAINT `FK_Mortgages`<br />
<br />
    FOREIGN KEY (`CID` , `ACN` )<br />
<br />
    REFERENCES `bankpage_`.`accounts` (`CID` , `ACN` )<br />
<br />
    ON DELETE NO ACTION<br />
<br />
    ON UPDATE NO ACTION);<br />
<br />
=================<br />
On execution I am getting the following error:<br />
ERROR 1005: Can't create table '.\bankpage_\mortgages.frm' (errno: 150)<br />
<br />
================<br />
Please help me<br />
I want to reference two columns of mortages table to accounts table]]></description>
            <dc:creator>Shashwat Tripathi</dc:creator>
            <category>Constraints</category>
            <pubDate>Mon, 18 Jul 2011 10:54:21 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?136,425885,425885#msg-425885</guid>
            <title>Selecting records that don't match a criteria (1 reply)</title>
            <link>http://forums.mysql.com/read.php?136,425885,425885#msg-425885</link>
            <description><![CDATA[ Hello,<br />
<br />
already 3 hours I try to constrict a query to my problem. Given the database table with those 5 records:<br />
<br />
PatientNumber | DrugType  <br />
-------------------------------------<br />
1 ___________ | A  <br />
1 ___________ | A<br />
2 ___________ | A<br />
2 ___________ | B<br />
2 ___________ | A<br />
<br />
Which represents the types of the drugs that have been given to a patient.<br />
<br />
How to consuct a MySQL query which will get me a record for a patient that have NEVER get drug from type B? In this particular case it should return the first and the second record (because patient 1 never got drug from type B).<br />
<br />
Thanks and best regards,<br />
<br />
Svetlomir Kasabov.]]></description>
            <dc:creator>skasab2s skasab2s</dc:creator>
            <category>Constraints</category>
            <pubDate>Mon, 18 Jul 2011 11:20:39 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?136,421784,421784#msg-421784</guid>
            <title>Inconsistent DB - Foreign key constraint fails (3 replies)</title>
            <link>http://forums.mysql.com/read.php?136,421784,421784#msg-421784</link>
            <description><![CDATA[ Hi all!<br />
<br />
As the subject indicates, I am getting the famous &quot;ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails&quot; message.<br />
<br />
But it's a bit strange since the schema didn't change for months and the system was running without problems. But two things happened that could have triggered the problem: 1) Our hosting provider restarted the server and 2.) I manually triggered the system processing data and killed the process once (application, not the db).<br />
<br />
Now I'm getting this problem. I read some other posts here, but it didn't help. - - The tables are all lower case letters<br />
- I'm using a terminal on a linux machine, no windows involved. <br />
- The key that it is referencing to is definitely existing. <br />
- I tried to left join the two tables to find out if there are any inconsistencies but there aren't any.<br />
- I created these two tables (see below) from scratch in a different db, entered the values in the one table, performed the very same insert statement and DID NOT get the error!<br />
<br />
Is it possible, that the database has entered any inconsitent state? If yes, is there any statement to check this?<br />
<br />
Thanks a lot!<br />
<br />
<br />
Here is some information:<br />
----------------------------------------------------------------------<br />
<br />
<pre class="bbcode">
mysql  Ver 14.12 Distrib 5.0.67, for suse-linux-gnu (i686) using readline 5.2

Connection id:          3231
Current database:       sbahn
Current user:           sbahn@localhost
SSL:                    Not in use
Current pager:          less
Using outfile:          ''
Using delimiter:        ;
Server version:         5.0.67 SUSE MySQL RPM
Protocol version:       10
Connection:             Localhost via UNIX socket
Server characterset:    utf8
Db     characterset:    utf8
Client characterset:    utf8
Conn.  characterset:    utf8
UNIX socket:            /var/lib/mysql/mysql.sock
Uptime:                 2 days 16 hours 24 min 30 sec

Threads: 1  Questions: 78  Slow queries: 0  Opens: 20  Flush tables: 1  Open tables: 14  Queries per second avg: 0.000
--------------

mysql&gt; select version();
+-----------+
| version() |
+-----------+
| 5.0.67    |
+-----------+



CREATE TABLE `t_betriebsstellen` (
  `kurzname` varchar(15) NOT NULL,
  PRIMARY KEY  (`kurzname`),
  UNIQUE KEY `UQ_t_betriebsstellen_kurzname` (`kurzname`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 


 t_zug_report | CREATE TABLE `t_zug_report` (
  `ist_datum` date NOT NULL,
  `zug_nr` int(11) NOT NULL,
  `ist_zeit` time NOT NULL,
  `soll_datum` date default NULL,
  `soll_zeit` time default NULL,
  `fehler_code` smallint(6) NOT NULL,
  `betriebsstelle` varchar(15) NOT NULL,
  `soll_gleis` int(11) NOT NULL,
  `ist_gleis` int(11) NOT NULL,
  `soll_ip` varchar(15) NOT NULL,
  `ist_ip` varchar(15) default NULL,
  `soll_wlan_nr` tinyint(4) NOT NULL,
  `ist_wlan_nr` tinyint(4) default NULL,
  `feldstaerke` float default NULL,
  PRIMARY KEY  (`ist_datum`,`zug_nr`,`ist_zeit`),
  KEY `IDX_betriebsstelle` (`betriebsstelle`),
  KEY `IDX_ist_datum` (`ist_datum`),
  KEY `IDX_zug_nr` (`zug_nr`),
  CONSTRAINT `FK_t_zug_report_t_betriebsstellen` FOREIGN KEY (`betriebsstelle`) REFERENCES `t_betriebsstellen` (`kurzname`) ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |

mysql&gt; select * from t_betriebsstellen;
+----------+
| kurzname |
+----------+
| BGB      |
| BLST     |
| BPLA     |
| BSGR     |
| BSO      |
| BSTO     |
| BTHF     |
+----------+
7 rows in set (0.00 sec)</pre>
<br />
When I do the following statement, I get the error:<br />
<br />
<pre class="bbcode">
insert into t_zug_report values ('2011-05-16',41020,'04:34:47',null,null,1,'BGB',7230,7230,'0.0.0.0',null,1,null,null);
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails (`sbahn/t_zug_report`, CONSTRAINT `FK_t_zug_report_t_betriebsstellen` FOREIGN KEY (`betriebsstelle`) REFERENCES `t_betriebsstellen` (`kurzname`) ON UPDATE CASCADE)
</pre>]]></description>
            <dc:creator>Jan Wedel</dc:creator>
            <category>Constraints</category>
            <pubDate>Tue, 31 May 2011 10:03:44 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?136,415208,415208#msg-415208</guid>
            <title>Date and Symbol constraint (1 reply)</title>
            <link>http://forums.mysql.com/read.php?136,415208,415208#msg-415208</link>
            <description><![CDATA[ I import data regularly form the following function:<br />
load data local infile 'C:\\Documents and Settings\\J\\Desktop\\import.csv' into table data fields terminated by ',' enclosed by '''' lines terminated by '\n'; <br />
<br />
The table structure is:<br />
CREATE TABLE `data` (<br />
  `Date` datetime DEFAULT NULL,<br />
  `Symbol` varchar(6) DEFAULT NULL,<br />
  `ClosingPrice` decimal(8,2) DEFAULT NULL,<br />
  KEY `Symbol` (`Symbol`)<br />
) ENGINE=InnoDB DEFAULT CHARSET=latin1$$<br />
<br />
I cannot edit all of the raw data so what I want to so is prevent duplicates entering the database. A duplicate is a row that has the same same symbol and same date. So, 1 entry for AAA '2011-04-01' is allowed but not<br />
AAA '2011-04-01' &amp; AAA '2011-04-01'<br />
<br />
What is the best way to put a constraint on this while importing?<br />
Furthermore, I would like to allow the data be updated if the ClosingPrice has changed.<br />
<br />
I thought a trigger might work:<br />
DELIMITER $$<br />
create trigger duplicate_check before insert on data for each row<br />
begin<br />
 if new.Date = (SELECT Date FROM data WHERE Date=new.Date AND Symbol=new.Symbol) then<br />
         call fail(’Duplicate data’);<br />
         #is there a way just to abort that 1 row insert here?<br />
         #where is the else function to allow the insert?<br />
 end if;<br />
end $$<br />
DELIMITER ;<br />
<br />
Where is the else function to allow the insert?<br />
Secondly, as the imported data doesn't have column labels how does the insert know which column is which as at the moment it just imports them in column order I think.]]></description>
            <dc:creator>jj ww</dc:creator>
            <category>Constraints</category>
            <pubDate>Tue, 05 Apr 2011 20:12:06 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?136,408464,408464#msg-408464</guid>
            <title>Some sort of constraint needed (2 replies)</title>
            <link>http://forums.mysql.com/read.php?136,408464,408464#msg-408464</link>
            <description><![CDATA[ Hi All,<br />
<br />
I have 3 tables set up similar to as follows:<br />
<pre class="bbcode">
CREATE TABLE AllProducts (ID INT, ProductType TINYINT(1), ProductID INT);

CREATE TABLE ProductA (ID INT, Product_Description VARCHAR(100));
CREATE TABLE ProductB (ID INT, Product_Description VARCHAR(100));

INSERT INTO TABLE ProductA VALUES (1,&quot;This product is a ...&quot;);
INSERT INTO TABLE ProductB VALUES (1,&quot;This product is a ...&quot;);
INSERT INTO TABLE AllProducts VALUES (1,1,1), (2,2,1);</pre>
Where in the AllProducts table, ProductType=1 refers to the ProductA table and ProductType=2 refers to ProductB table.<br />
<br />
I would like to have some sort of foreign key constraint in AllProducts table, so that when a new row is inserted into it with ProductType=1, it would look up to see if that ProductID exists in the ProductA's ID column, and of course, a row cannot be deleted in ProductA if a reference exists in AllProducts.<br />
<br />
Does anyone know how this could be done apart from writing triggers?<br />
<br />
Cheers.]]></description>
            <dc:creator>Eddie Lau</dc:creator>
            <category>Constraints</category>
            <pubDate>Fri, 18 Feb 2011 17:47:32 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?136,408235,408235#msg-408235</guid>
            <title>Unsigned, AutoIncrement (2 replies)</title>
            <link>http://forums.mysql.com/read.php?136,408235,408235#msg-408235</link>
            <description><![CDATA[ Hi,<br />
<br />
I look for a posibility to read the value Unsigned and AutoIncrement form a field in the information_schema. In the manual I don't find any information. <br />
<br />
I found information for key, not null and unique, but not the other constraints.<br />
<br />
Can anybody help.]]></description>
            <dc:creator>Winfried Palm</dc:creator>
            <category>Constraints</category>
            <pubDate>Mon, 21 Feb 2011 13:18:23 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?136,391782,391782#msg-391782</guid>
            <title>FOREIGN KEY ON UPDATE CASCADE does NOT work with SELF REFERENCE (1 reply)</title>
            <link>http://forums.mysql.com/read.php?136,391782,391782#msg-391782</link>
            <description><![CDATA[ Hello to everyone,<br />
<br />
I found a very similar issue here:<br />
<a href="http://forums.mysql.com/read.php?136,300573,300573#msg-300573"  rel="nofollow">http://forums.mysql.com/read.php?136,300573,300573#msg-300573</a><br />
but it appears to be closed without any reply, so before posting it as a bug I would inquire here whether anyone has any known solution to it or it is an actual bug.<br />
<br />
I think it is an important issue in general.<br />
<br />
Here we go:<br />
<br />
PROBLEM: FOREIGN KEY ON UPDATE CASCADE does NOT work with SELF REFERENCE<br />
<br />
PURPOSE: Ensuring that when updating the parent value, the related values in childs get updated accordingly.<br />
<br />
SUMMARY: Once such foreing key relationship is set up within the same table, attempts to update the key field of a parent having childs, not only do not work, but generate an error as well.<br />
<br />
REFERENCE:<br />
MySQL Manual, in section:<br />
&quot;14.2.6.4. FOREIGN KEY Constraints&quot;<br />
it reads:<br />
&quot;Note that InnoDB supports foreign key references within a table. In these cases, “child table records” really refers to dependent records within the same table.&quot;<br />
<br />
HOW TO REPRODUCE IT:<br />
<br />
- Done with:<br />
<br />
Windows 7<br />
XAMPP for Windows Version 1.7.3<br />
MySQL: 5.1.41<br />
PhpMyAdmin 3.2.4<br />
<br />
- Create the table together with the foreign key reference pointing to itself:<br />
<br />
CREATE TABLE `table` <br />
(<br />
id INT NOT NULL, <br />
parent_id INT, <br />
PRIMARY KEY (id),<br />
FOREIGN KEY (parent_id) <br />
REFERENCES `table`(id) <br />
ON DELETE CASCADE <br />
ON UPDATE CASCADE<br />
)<br />
ENGINE=INNODB<br />
<br />
- Insert parent record:<br />
<br />
INSERT INTO `table` (<br />
`id` ,<br />
`parent_id` <br />
)<br />
VALUES (<br />
'0', NULL <br />
);<br />
<br />
- Insert child record:<br />
<br />
INSERT INTO `test`.`table` (<br />
`id` ,<br />
`parent_id` <br />
)<br />
VALUES (<br />
'1', '0'<br />
);<br />
<br />
- Attempt to update parent's related field:<br />
<br />
UPDATE `table` SET `id` = 2 WHERE `table`.`id` = 0 <br />
<br />
- I'd expect both parent's and child's fields updated; instead, the above returns the following error (test done with PhpMyAdmin, within database named `test`):<br />
<br />
#1451 - Cannot delete or update a parent row: a foreign key constraint fails (`test`.`table`, CONSTRAINT `table_ibfk_1` FOREIGN KEY (`parent_id`) REFERENCES `table` (`id`) ON DELETE CASCADE ON UPDATE CASCADE)<br />
<br />
Why?<br />
Perhaps did MySQL refuse to update the parent row because it considers that parent being a child to another parent (which does non exist, by the way)?<br />
So I also tested it with such parent record with id = NULL in existence (and to do so I created the table as not having any primary key but a simple index unique replacing it). Does not work either: same update attempt, same error message as above.<br />
<br />
Any clue? Is there a way out?<br />
I do have to solve it, and I think many others may as well, so thanks a lot in advance for any help.]]></description>
            <dc:creator>Luca Esculapio</dc:creator>
            <category>Constraints</category>
            <pubDate>Wed, 08 Dec 2010 07:37:43 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?136,391758,391758#msg-391758</guid>
            <title>foreign-key / import (no replies)</title>
            <link>http://forums.mysql.com/read.php?136,391758,391758#msg-391758</link>
            <description><![CDATA[ I am exporting data from MySQL 5.1.22-rc via the phpMyAdmin 2.11.7.1 interface and importing the data into MySQL 5.2.29CE. I was able to import all of the data into MySQL 5.2.29CE successfully, but I had to comment out foreign-key statements to do so.<br />
<br />
Now I am trying to execute/apply the foreign-key statements on the tables in MySQL 5.2.29CE. I was able to successfully execute/apply the GROUP2 updates, but not GROUP1. The statements in GROUP1 generate the following error: Error Code: 1005Can't create table 'scs.#sql-68c_f(errno: 121).<br />
<br />
Do you see something in the code (which was generated by phpMyAdmin to export the data) that would cause that error?<br />
<br />
select @@foreign_key_checks;<br />
SET foreign_key_checks = 0;<br />
<br />
-- GROUP1: NOT executed successfully; 10.26.10<br />
<br />
SET SQL_MODE=&quot;NO_AUTO_VALUE_ON_ZERO&quot;;<br />
SET foreign_key_checks = 0;<br />
USE scs;<br />
<br />
ALTER TABLE `TBL_ShowNote`<br />
ADD CONSTRAINT FK_TBL_ShowNote_TBL_Show         FOREIGN KEY (Show_ID)         REFERENCES TBL_Show (Show_ID)                 ON DELETE NO ACTION ON UPDATE NO ACTION;<br />
<br />
ALTER TABLE `TBL_ShowNote`<br />
ADD CONSTRAINT FK_TBL_ShowNote_TBL_ShowNoteType FOREIGN KEY (ShowNoteType_ID) REFERENCES TBL_ShowNoteType (ShowNoteType_ID) ON DELETE NO ACTION ON UPDATE NO ACTION;<br />
<br />
-- GROUP2: executed successfully; 10.26.10<br />
<br />
SET SQL_MODE=&quot;NO_AUTO_VALUE_ON_ZERO&quot;;<br />
SET foreign_key_checks = 0;<br />
USE scs;<br />
<br />
ALTER TABLE `RETS_Log`<br />
  ADD CONSTRAINT RETS_Log_ibfk_1 FOREIGN KEY (listnum) REFERENCES PROPMAIN (listnum);<br />
<br />
--<br />
-- Constraints for table `TBL_Announce`<br />
--<br />
ALTER TABLE `TBL_Announce`<br />
  ADD CONSTRAINT FK_TBL_Announce_TBL_AnnounceType FOREIGN KEY (AnnounceType_ID) REFERENCES TBL_AnnounceType (AnnounceType_ID) ON DELETE NO ACTION ON UPDATE NO ACTION;<br />
<br />
--<br />
-- Constraints for table `TBL_Association`<br />
--<br />
ALTER TABLE `TBL_Association`<br />
  ADD CONSTRAINT FK_TBL_UserAssociation_TBL_Company FOREIGN KEY (Company_ID) REFERENCES TBL_Company (Company_ID) ON DELETE NO ACTION ON UPDATE NO ACTION;<br />
<br />
--<br />
-- Constraints for table `TBL_CallTagxRef`<br />
--<br />
ALTER TABLE `TBL_CallTagxRef`<br />
  ADD CONSTRAINT FK_TBL_CallTagxRef_TBL_CallTag FOREIGN KEY (CallTag_ID) REFERENCES TBL_CallTag (CallTag_ID) ON DELETE NO ACTION ON UPDATE NO ACTION,<br />
  ADD CONSTRAINT FK_TBL_CallTagxRef_TBL_Message FOREIGN KEY (Message_ID) REFERENCES TBL_Message (Message_ID) ON DELETE NO ACTION ON UPDATE NO ACTION;<br />
<br />
--<br />
-- Constraints for table `TBL_Company`<br />
--<br />
ALTER TABLE `TBL_Company`<br />
  ADD CONSTRAINT FK_TBL_Company_TBL_CompanyType FOREIGN KEY (CompanyType_ID) REFERENCES TBL_CompanyType (CompanyType_ID) ON DELETE NO ACTION ON UPDATE NO ACTION,<br />
  ADD CONSTRAINT FK_TBL_Company_TBL_State FOREIGN KEY (State_ID) REFERENCES TBL_State (State_ID) ON DELETE NO ACTION ON UPDATE NO ACTION;<br />
<br />
--<br />
-- Constraints for table `TBL_CompanyServices`<br />
--<br />
ALTER TABLE `TBL_CompanyServices`<br />
  ADD CONSTRAINT FK_TBL_CompanyServices_TBL_Company FOREIGN KEY (Company_ID) REFERENCES TBL_Company (Company_ID) ON DELETE NO ACTION ON UPDATE NO ACTION,<br />
  ADD CONSTRAINT FK_TBL_CompanyServices_TBL_County FOREIGN KEY (County_ID) REFERENCES TBL_County (County_ID) ON DELETE NO ACTION ON UPDATE NO ACTION,<br />
  ADD CONSTRAINT FK_TBL_CompanyServices_TBL_Services FOREIGN KEY (Services_ID) REFERENCES TBL_Services (Services_ID) ON DELETE NO ACTION ON UPDATE NO ACTION;<br />
<br />
--<br />
-- Constraints for table `TBL_ContactType`<br />
--<br />
ALTER TABLE `TBL_ContactType`<br />
  ADD CONSTRAINT FK_TBL_ContactType_TBL_ContactDevice FOREIGN KEY (ContactDevice_ID) REFERENCES TBL_ContactDevice (ContactDevice_ID) ON DELETE NO ACTION ON UPDATE NO ACTION;<br />
<br />
--<br />
-- Constraints for table `TBL_Coordinator`<br />
--<br />
ALTER TABLE `TBL_Coordinator`<br />
  ADD CONSTRAINT FK_TBL_Coordinator_TBL_User FOREIGN KEY (User_ID) REFERENCES TBL_User (User_ID) ON DELETE NO ACTION ON UPDATE NO ACTION;<br />
<br />
--<br />
-- Constraints for table `TBL_County`<br />
--<br />
ALTER TABLE `TBL_County`<br />
  ADD CONSTRAINT FK_TBL_County_TBL_State FOREIGN KEY (State_ID) REFERENCES TBL_State (State_ID) ON DELETE NO ACTION ON UPDATE NO ACTION;<br />
<br />
--<br />
-- Constraints for table `TBL_Document`<br />
--<br />
ALTER TABLE `TBL_Document`<br />
  ADD CONSTRAINT FK_TBL_Document_TBL_Company FOREIGN KEY (Company_ID) REFERENCES TBL_Company (Company_ID) ON DELETE NO ACTION ON UPDATE NO ACTION,<br />
  ADD CONSTRAINT FK_TBL_Document_TBL_DocumentFormat FOREIGN KEY (DocumentFormat_ID) REFERENCES TBL_DocumentFormat (DocumentFormat_ID) ON DELETE NO ACTION ON UPDATE NO ACTION,<br />
  ADD CONSTRAINT FK_TBL_Document_TBL_DocumentType FOREIGN KEY (DocumentType_ID) REFERENCES TBL_DocumentType (DocumentType_ID) ON DELETE NO ACTION ON UPDATE NO ACTION;<br />
<br />
--<br />
-- Constraints for table `TBL_Features`<br />
--<br />
ALTER TABLE `TBL_Features`<br />
  ADD CONSTRAINT FK_TBL_Features_TBL_PropMain FOREIGN KEY (propid) REFERENCES TBL_PropMain (propid) ON DELETE NO ACTION ON UPDATE NO ACTION;<br />
<br />
--<br />
-- Constraints for table `TBL_Field`<br />
--<br />
ALTER TABLE `TBL_Field`<br />
  ADD CONSTRAINT FK_TBL_Field_TBL_Group FOREIGN KEY (groupid) REFERENCES TBL_Group (groupid) ON DELETE NO ACTION ON UPDATE NO ACTION;<br />
<br />
--<br />
-- Constraints for table `TBL_Inbound`<br />
--<br />
ALTER TABLE `TBL_Inbound`<br />
  ADD CONSTRAINT FK_TBL_Inbound_TBL_User FOREIGN KEY (User_ID) REFERENCES TBL_User (User_ID) ON DELETE NO ACTION ON UPDATE NO ACTION;<br />
<br />
--<br />
-- Constraints for table `TBL_Location`<br />
--<br />
ALTER TABLE `TBL_Location`<br />
  ADD CONSTRAINT FK_TBL_Location_TBL_Company FOREIGN KEY (Company_ID) REFERENCES TBL_Company (Company_ID) ON DELETE NO ACTION ON UPDATE NO ACTION;<br />
<br />
--<br />
-- Constraints for table `TBL_Message`<br />
--<br />
ALTER TABLE `TBL_Message`<br />
  ADD CONSTRAINT FK_TBL_Message_TBL_Advertise FOREIGN KEY (Advertise_ID) REFERENCES TBL_Advertise (Advertise_ID) ON DELETE NO ACTION ON UPDATE NO ACTION,<br />
  ADD CONSTRAINT FK_TBL_Message_TBL_MessageType FOREIGN KEY (MessageType_ID) REFERENCES TBL_MessageType (MessageType_ID) ON DELETE NO ACTION ON UPDATE NO ACTION,<br />
  ADD CONSTRAINT FK_TBL_Message_TBL_User FOREIGN KEY (User_ID) REFERENCES TBL_User (User_ID) ON DELETE NO ACTION ON UPDATE NO ACTION;<br />
<br />
--<br />
-- Constraints for table `TBL_Notify`<br />
--<br />
ALTER TABLE `TBL_Notify`<br />
  ADD CONSTRAINT FK_TBL_Notify_TBL_NotifyType FOREIGN KEY (NotifyType_ID) REFERENCES TBL_NotifyType (NotifyType_ID) ON DELETE NO ACTION ON UPDATE NO ACTION,<br />
  ADD CONSTRAINT FK_TBL_Notify_TBL_User FOREIGN KEY (User_ID) REFERENCES TBL_User (User_ID) ON DELETE NO ACTION ON UPDATE NO ACTION;<br />
<br />
--<br />
-- Constraints for table `TBL_Permission`<br />
--<br />
ALTER TABLE `TBL_Permission`<br />
  ADD CONSTRAINT FK_TBL_Permission_TBL_PermissionType FOREIGN KEY (PermissionType_ID) REFERENCES TBL_PermissionType (PermissionType_ID) ON DELETE NO ACTION ON UPDATE NO ACTION;<br />
<br />
--<br />
-- Constraints for table `TBL_PermissionCompanyType`<br />
--<br />
ALTER TABLE `TBL_PermissionCompanyType`<br />
  ADD CONSTRAINT FK_TBL_PermissionCompanyType_TBL_Permission FOREIGN KEY (Permission_ID) REFERENCES TBL_Permission (Permission_ID) ON DELETE NO ACTION ON UPDATE NO ACTION;<br />
<br />
--<br />
-- Constraints for table `TBL_PollDesign`<br />
--<br />
ALTER TABLE `TBL_PollDesign`<br />
  ADD CONSTRAINT FK_TBL_PollDesign_TBL_PollName FOREIGN KEY (PollName_ID) REFERENCES TBL_PollName (PollName_ID) ON DELETE NO ACTION ON UPDATE NO ACTION,<br />
  ADD CONSTRAINT FK_TBL_PollDesign_TBL_PollQuestionType FOREIGN KEY (PollQuestionType_ID) REFERENCES TBL_PollQuestionType (PollQuestionType_ID) ON DELETE NO ACTION ON UPDATE NO ACTION;<br />
<br />
--<br />
-- Constraints for table `TBL_PollName`<br />
--<br />
ALTER TABLE `TBL_PollName`<br />
  ADD CONSTRAINT FK_TBL_PollName_TBL_Company FOREIGN KEY (Company_ID) REFERENCES TBL_Company (Company_ID) ON DELETE NO ACTION ON UPDATE NO ACTION;<br />
<br />
--<br />
-- Constraints for table `TBL_PollRequest`<br />
--<br />
ALTER TABLE `TBL_PollRequest`<br />
  ADD CONSTRAINT FK_TBL_PollRequest_TBL_PollName FOREIGN KEY (PollName_ID) REFERENCES TBL_PollName (PollName_ID) ON DELETE NO ACTION ON UPDATE NO ACTION,<br />
  ADD CONSTRAINT FK_TBL_PollRequest_TBL_User FOREIGN KEY (User_ID) REFERENCES TBL_User (User_ID) ON DELETE NO ACTION ON UPDATE NO ACTION;<br />
<br />
--<br />
-- Constraints for table `TBL_PollValue`<br />
--<br />
ALTER TABLE `TBL_PollValue`<br />
  ADD CONSTRAINT FK_TBL_PollValue_TBL_PollRequest FOREIGN KEY (PollRequest_ID) REFERENCES TBL_PollRequest (PollRequest_ID) ON DELETE NO ACTION ON UPDATE NO ACTION;<br />
<br />
--<br />
-- Constraints for table `TBL_Promotion`<br />
--<br />
ALTER TABLE `TBL_Promotion`<br />
  ADD CONSTRAINT FK_TBL_Promotion_TBL_Company FOREIGN KEY (Company_ID) REFERENCES TBL_Company (Company_ID) ON DELETE NO ACTION ON UPDATE NO ACTION;<br />
<br />
--<br />
-- Constraints for table `TBL_Prop1`<br />
--<br />
ALTER TABLE `TBL_Prop1`<br />
  ADD CONSTRAINT FK_TBL_Prop1_TBL_PropMain FOREIGN KEY (propid) REFERENCES TBL_PropMain (propid) ON DELETE NO ACTION ON UPDATE NO ACTION;<br />
<br />
--<br />
-- Constraints for table `TBL_PropMain`<br />
--<br />
ALTER TABLE `TBL_PropMain`<br />
  ADD CONSTRAINT FK_TBL_PropMain_TBL_Status FOREIGN KEY (`status`) REFERENCES TBL_Status (Status_ID) ON DELETE NO ACTION ON UPDATE NO ACTION;<br />
<br />
--<br />
-- Constraints for table `TBL_PropPromotion`<br />
--<br />
ALTER TABLE `TBL_PropPromotion`<br />
  ADD CONSTRAINT FK_TBL_PromotionProp_TBL_Promotion FOREIGN KEY (Promotion_ID) REFERENCES TBL_Promotion (Promotion_ID) ON DELETE NO ACTION ON UPDATE NO ACTION;<br />
<br />
--<br />
-- Constraints for table `TBL_PropRoom`<br />
--<br />
ALTER TABLE `TBL_PropRoom`<br />
  ADD CONSTRAINT FK_TBL_PropRoom_TBL_PropMain FOREIGN KEY (propid) REFERENCES TBL_PropMain (propid) ON DELETE NO ACTION ON UPDATE NO ACTION,<br />
  ADD CONSTRAINT FK_TBL_PropRoom_TBL_Room FOREIGN KEY (room_id) REFERENCES TBL_Room (RoomID) ON DELETE NO ACTION ON UPDATE NO ACTION;<br />
<br />
--<br />
-- Constraints for table `TBL_PropShow`<br />
--<br />
ALTER TABLE `TBL_PropShow`<br />
  ADD CONSTRAINT FK_TBL_PropShow_TBL_ShowReply FOREIGN KEY (ShowReply_ID) REFERENCES TBL_ShowReply (ShowReply_ID) ON DELETE NO ACTION ON UPDATE NO ACTION,<br />
  ADD CONSTRAINT FK_TBL_PropShow_TBL_User FOREIGN KEY (User_ID) REFERENCES TBL_User (User_ID) ON DELETE NO ACTION ON UPDATE NO ACTION;<br />
<br />
--<br />
-- Constraints for table `TBL_Show`<br />
--<br />
ALTER TABLE `TBL_Show`<br />
  ADD CONSTRAINT FK_TBL_Show_TBL_AppointmentType FOREIGN KEY (AppointmentType_ID) REFERENCES TBL_AppointmentType (AppointmentType_ID) ON DELETE NO ACTION ON UPDATE NO ACTION,<br />
  ADD CONSTRAINT FK_TBL_Show_TBL_ShowReply FOREIGN KEY (ShowReply_ID) REFERENCES TBL_ShowReply (ShowReply_ID) ON DELETE NO ACTION ON UPDATE NO ACTION,<br />
  ADD CONSTRAINT FK_TBL_Show_TBL_User FOREIGN KEY (User_ID) REFERENCES TBL_User (User_ID) ON DELETE NO ACTION ON UPDATE NO ACTION,<br />
  ADD CONSTRAINT TBL_Show_ibfk_1 FOREIGN KEY (ShowStatus_ID) REFERENCES TBL_ShowStatus (ShowStatus_ID);<br />
<br />
--<br />
-- Constraints for table `TBL_State`<br />
--<br />
ALTER TABLE `TBL_State`<br />
  ADD CONSTRAINT FK_TBL_State_TBL_Country FOREIGN KEY (Country_ID) REFERENCES TBL_Country (Country_ID) ON DELETE NO ACTION ON UPDATE NO ACTION;<br />
<br />
--<br />
-- Constraints for table `TBL_User`<br />
--<br />
ALTER TABLE `TBL_User`<br />
  ADD CONSTRAINT FK_TBL_User_TBL_Challenge FOREIGN KEY (Challenge_ID) REFERENCES TBL_Challenge (Challenge_ID) ON DELETE NO ACTION ON UPDATE NO ACTION,<br />
  ADD CONSTRAINT FK_TBL_User_TBL_Location FOREIGN KEY (Location_ID) REFERENCES TBL_Location (Location_ID) ON DELETE NO ACTION ON UPDATE NO ACTION;<br />
<br />
--<br />
-- Constraints for table `TBL_UserContact`<br />
--<br />
ALTER TABLE `TBL_UserContact`<br />
  ADD CONSTRAINT FK_TBL_UserContact_TBL_ContactType FOREIGN KEY (ContactType_ID) REFERENCES TBL_ContactType (ContactType_ID) ON DELETE NO ACTION ON UPDATE NO ACTION,<br />
  ADD CONSTRAINT FK_TBL_UserContact_TBL_User FOREIGN KEY (User_ID) REFERENCES TBL_User (User_ID) ON DELETE NO ACTION ON UPDATE NO ACTION;<br />
<br />
--<br />
-- Constraints for table `TBL_UserPermission`<br />
--<br />
ALTER TABLE `TBL_UserPermission`<br />
  ADD CONSTRAINT FK_TBL_UserPermission_TBL_Permission FOREIGN KEY (Permission_ID) REFERENCES TBL_Permission (Permission_ID) ON DELETE NO ACTION ON UPDATE NO ACTION,<br />
  ADD CONSTRAINT FK_TBL_UserPermission_TBL_User FOREIGN KEY (User_ID) REFERENCES TBL_User (User_ID) ON DELETE NO ACTION ON UPDATE NO ACTION;<br />
  <br />
Thanks!<br />
<br />
JDBA]]></description>
            <dc:creator>Junior DBA</dc:creator>
            <category>Constraints</category>
            <pubDate>Tue, 26 Oct 2010 17:04:54 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?136,389546,389546#msg-389546</guid>
            <title>Unique constraint on case insensitive varchar column? (4 replies)</title>
            <link>http://forums.mysql.com/read.php?136,389546,389546#msg-389546</link>
            <description><![CDATA[ Hi All,<br />
<br />
I'm trying to create a table with a case insensitive varchar column as unique constraint. I'm using utf8 char-set and utf8-generic-ci collaction. So the search is case insensitive. But I still can insert another records with same string but different case. I tried to use unique(upper(columnname)), but MySQL complain syntax error. Anybody know a way to do it?<br />
<br />
Thanks<br />
<br />
Lifeng]]></description>
            <dc:creator>Lifeng Wang</dc:creator>
            <category>Constraints</category>
            <pubDate>Fri, 15 Oct 2010 09:35:03 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?136,383613,383613#msg-383613</guid>
            <title>Default value is not used (4 replies)</title>
            <link>http://forums.mysql.com/read.php?136,383613,383613#msg-383613</link>
            <description><![CDATA[ Is anyone aware of a reason that a table with a default constraint on one of the fields would ignore the default value when creating a new row?<br />
<br />
We have an application written in Delphi that has been inserting new rows in this table for many months with the default value.  Just a few days ago, the new rows began to be inserted with the field value of 0 instead of the default value 1.  The field type is tinyint, unsigned.  The application code has not changed, nor am I aware of any MySQL patches to the system.<br />
<br />
Obviously something has changed, but I'm not sure what else to look for.]]></description>
            <dc:creator>Kimberly Rowe</dc:creator>
            <category>Constraints</category>
            <pubDate>Fri, 17 Sep 2010 14:47:00 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?136,374783,374783#msg-374783</guid>
            <title>Conditional Constraint (no replies)</title>
            <link>http://forums.mysql.com/read.php?136,374783,374783#msg-374783</link>
            <description><![CDATA[ I have several association tables that have a primary key based upon, for example,  entity id, entity type and address id.  An entity can be a person (prsn_id), an organization (org_id) or a location (loc_id). <br />
<br />
How do I create (a) foreign key(s) that kicks in depending upon the entity_type?  I cannot just create these foreign keys...<br />
ALTER TABLE entm_ent_eml_assn ADD FOREIGN KEY fk_ent_id_prsn REFERENCES prsn_prsn(prsn_id);<br />
ALTER TABLE entm_ent_eml_assn ADD FOREIGN KEY fk_ent_id_org REFERENCES org_org(org_id);<br />
ALTER TABLE entm_ent_eml_assn ADD FOREIGN KEY fk_ent_id_loc REFERENCES loc_loc(loc_id);<br />
ALTER TABLE entm_ent_eml_assn ADD FOREIGN KEY fk_ent_typ_ldat_id REFERENCES ldat_lkup_data(ldat_id);<br />
ALTER TABLE entm_ent_eml_assn ADD FOREIGN KEY fk_eml_typ_ldat_id REFERENCES ldat_lkup_data(ldat_id);<br />
<br />
... because the ent_id and ent_typ_id are not tied together.  It is possible to have the same ent_id but different ent_typ_ids.  I don't want to disallow a valid ent_id if it's a prsn when the same ent_id might exist as an organization, for example. Even it I do a UNIQUE KEY constraint instead, I have the same issue.<br />
<br />
What is the best way to manage this kind of conditional constraint?  <br />
<br />
Thanks for your help!<br />
<br />
Sue]]></description>
            <dc:creator>Susan Hurst</dc:creator>
            <category>Constraints</category>
            <pubDate>Mon, 05 Jul 2010 02:40:46 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?136,374554,374554#msg-374554</guid>
            <title>date constraint (3 replies)</title>
            <link>http://forums.mysql.com/read.php?136,374554,374554#msg-374554</link>
            <description><![CDATA[ Dear all,<br />
<br />
can I define a date defintion intervall beginning from a start date?<br />
Tthe date column should be not smaller than project date and not greater than sysdate - all other dates before or behind would be false data and need to be shown as a warning. How can I realise this? <br />
<br />
Example:<br />
<br />
Project Start - 01.01.2010<br />
wrong value 15.12.2009 (before project date)<br />
wrong value 15.12.2010 (greate than today)<br />
<br />
Greetings form Germany,<br />
<br />
Cathy]]></description>
            <dc:creator>Katja Fink</dc:creator>
            <category>Constraints</category>
            <pubDate>Mon, 05 Jul 2010 12:08:45 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?136,362682,362682#msg-362682</guid>
            <title>How to create a table that distinguishes greeks 'ο' from 'ό'  on INSERT but considers both identical on SELECT (3 replies)</title>
            <link>http://forums.mysql.com/read.php?136,362682,362682#msg-362682</link>
            <description><![CDATA[ Hi there <br />
I am in the process of building a database. <br />
One of the tables would be the SURNAMES table.<br />
<br />
eg. table SURNAMES<br />
SurnameID   BIGINT AUTOINCREMENT <br />
Surname   VARCHAR(100) UNIQUE<br />
<br />
<br />
I need to declare the table in a manner where<br />
<br />
1) given that the name 'Κόντου' exists <br />
the surname 'Κοντού' would be allowed to be added in the table <br />
while an attempt to insert the identical to the existing one 'Κόντου' would fail.<br />
<br />
BUT<br />
<br />
when I run the query<br />
SELECT * FROM Surnames where Surname LIKE CONCAT ('Κον', '%') <br />
would return both records.<br />
Κόντου<br />
Κοντού<br />
<br />
So far I have tried the greek_bin collation which works fine restricting the insertion of identical surnames but allowing the insertion of both of the above. The SELECT query though does NOT return both of them.<br />
<br />
On the other hand the greek_default or the greek_general DOES allow identical insertions!!! despite the UNIQUE declaration of the Surname field.<br />
<br />
I would value your expert opinion<br />
Thanx a million]]></description>
            <dc:creator>Ni Angel</dc:creator>
            <category>Constraints</category>
            <pubDate>Wed, 14 Apr 2010 11:12:43 +0000</pubDate>
        </item>
    </channel>
</rss>
