Hi! I would like to change the primary key in my record and use another field instead (the created field would be a concat() from other two fields).
Even though I have been trying, I´m finding trouble when trying to change the condition of primary key and give it to another field. I don´t want this primary key to be AUTO-INCREMENT and, when I try to put another field as primary key, an error occurs. Is it possible to eliminate the primary key and convert the other one into a primary key?
Otherwise, how can I solve this?
Discussion posts and replies are publicly visible
I think you can solve the issue by removing the auto-increment on your concatenated key.
You should then be able to run your statement.
The auto increment is in my primary key (not in the concatenated one, this last is the one I want to change to my primary key)
I retired the auto-increment from the primary key and tried to change the primary key, but this error appears:
There is already a duplicate value in that field. You need to remove that first.
Hi carlosp5114
-- This set of SQL queries is used to update the primary key from one column to another column in the database. -- By executing these three queries, the database will be updated with a new column as the primary key, set to auto-increment. -- Additionally, in the record type, you can make corresponding changes as recommended by Appian. -- Step 1: Change the data type of the new column to INT(11) and mark it as NOT NULL. ALTER TABLE table_name CHANGE `column_name` `column_name` INT(11) NOT NULL; -- Step 2: Drop the existing primary key constraint from the table. ALTER TABLE table_name DROP PRIMARY KEY; -- Step 3: Add the new column as the primary key with auto-increment. ALTER TABLE table_name ADD COLUMN `new_column_name` INT AUTO_INCREMENT PRIMARY KEY;
Alright. I have to options to continue (for what I´ve searched) and would like your advice:
1) "Index" another primary key (in this case, I would have 2 primary keys, I don´t know if it is a correct approach)
2) Eliminate the actual primary key and substitute it for the other one (I remember that when I tried, it gave me an error when trying to eliminate it in the record, there was a warning message of mapping)
3) Only change the condition of primary key from one field to another (the variable I want to retire from primary key is auto-increment, and the new one isn´t)
Thanks a lot! Only one thing, I want my NEW primary key to be a TEXT, and I don´t want it to be autoIncrement. In my case, I want to create it in the process model as a CONCAT() of two fields of the record, as my identifier
Can I use your code with the new primary key as a text, and without putting it as AutoIncrement?
Trying to use a non-unique value as a primary key contradicts the nature of a primary key. That's my advice.
Primary keys mostly be Number (Integer) data types. They perform better than primary keys using text data types because integers are processed quicker and are easier to sort and index.
Yes, You can use by below query, remaining all are same steps we needs to follow.
-- Step 3: Add back the primary key constraint ALTER TABLE table_name ADD PRIMARY KEY (`new_column_name`);
Thanks! In the end I opted for creating a new primary key indexing to the first one (2 primary keys):
The fact is that, in my process, I have the following error:
I suppose I have to change the value of my second primary key ("CONCAT_...") to Null--> yes, but when I try to change it and save my edition doesn´t appear:
1) Base Configuration of my second primary key
2) Change I´m trying to do (it does not save)
3) Changes not saved (still "None" and not null by default)
I would like to know if this new primary key can be "null" as a default value and, if not, what can I do to fix the error! Thanks a lot!