![]() ![]() the primary key INTO the first field record (w/o adding an additional 'id' field, as stated earlier. $query = "ALTER TABLE racehorses ADD id INT NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (id)" This an end result sought (TABLE DESCRIPTION). ![]() This a table currently created - Number of Records found: 4 name VARCHAR(20) YES How to write PHP to ALTER the already existing field (name, in this example) to make it a primary key? W/o, of course, adding any additional 'id' fields to the table. But for now I wanted to share this solution to a more challenging version of the original question in case others ran into this situation. I am guessing that I need to tear down all foreign keys before doing the ALTER table and then rebuild them afterwards. #1025 - Error on rename of './zap/#sql-da07_6d' to './zap/SAKAI_USER_ID_MAP' (errno: 150) If your table already exists and you wish to add a primary key later, you can not use the ALTER TABLE statement to create a primary key. I get this message when I try to do a more complex example with an incoming foreign key from another table. What I have not been able to get working is the situation where there are incoming FOREIGN KEYs that already point at the USER_ID field. With the "DROP TABLE" at the top, you can run this over and over to experiment with variations. When this is done, the _USER_ID field exists and has all number values for the primary key exactly as you would expect. A table can have only ONE primary key and in the table, this primary key can consist of single or multiple columns (fields). Primary keys must contain UNIQUE values, and cannot contain NULL values. INSERT INTO SAKAI_USER_ID_MAP VALUES ('postmaster', 'postmaster') ĪDD _USER_ID INT AUTO_INCREMENT NOT NULL FIRST, The PRIMARY KEY constraint uniquely identifies each record in a table. INSERT INTO SAKAI_USER_ID_MAP VALUES ('admin', 'admin') I was able to adapt these instructions take a table with an existing non-increment primary key, and add an incrementing primary key to the table and create a new composite primary key with both the old and new keys as a composite primary key using the following code: DROP TABLE IF EXISTS SAKAI_USER_ID_MAP ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |