santalea
07-10-2006, 09:50 PM
how do i initialise the primary key if i am using mysql instead of microsoft access?
|
Click to See Complete Forum and Search --> : Primary Key santalea 07-10-2006, 09:50 PM how do i initialise the primary key if i am using mysql instead of microsoft access? NogDog 07-10-2006, 09:56 PM Not sure what you mean by "initialise". Primary key just means that the field in question must (1) be unique and (2) is indexed - there's really nothing to be initialised (that I'm aware of). If you're talking about an auto-incremented integer field, when defining the table you can set the starting auto-increment value by adding auto_increment=123 in the table options section at the end of the table definition. thoughtcube 07-11-2006, 02:44 AM Once you give a field the property "primary key", it immediately 'gets into play'. Nothing more is needed. This is how MySQL works, and every other RDBMS I am familiar with. chazzy 07-11-2006, 08:23 AM This is how MySQL works, and every other RDBMS I am familiar with. Actually you're supposed to have the capabilities of turning off the keys whenever you want. thoughtcube 07-11-2006, 08:28 AM Actually you're supposed to have the capabilities of turning off the keys whenever you want. Yes, you're right. MySQL can do that, for example. But, by default, a defined key is enforced, until you make some change to the settings. chazzy 07-11-2006, 09:58 AM mysql has no "disable key" thoughtcube 07-11-2006, 10:16 AM mysql has no "disable key" As far as I know - yes and no. The MySQL ALTER TABLE (http://dev.mysql.com/doc/refman/5.0/en/alter-table.html) command has a DISABLE KEYS clause, but only for nonunique indexes. So, this is irrelevant for primary keys. sitehatchery 07-11-2006, 10:19 AM On an Insert statement, you can "initialise" an auto incrementing primary key by setting it to null. chazzy 07-11-2006, 11:50 AM As far as I know - yes and no. The MySQL ALTER TABLE (http://dev.mysql.com/doc/refman/5.0/en/alter-table.html) command has a DISABLE KEYS clause, but only for nonunique indexes. So, this is irrelevant for primary keys. The problem with that is that the constraint is supposed to be considered its own entity, entirely separate from the table. of course it only exists as long as the table exists, but its status shouldn't be controlled by the table in that way. So yes, you can disable a key by altering a table but you can't alter a key's status by itself. webdeveloper.com
Copyright Internet.com Inc., All Rights Reserved. |