Reputation:
I have a column A
; I want to be able to have A[0]
column to contain the latest value, A[1]
to contain the most recent and so forth. Is this possible? If not is there an alternative?
Upvotes: 0
Views: 229
Reputation: 51008
That is not the correct way to model data in SQL. Instead, you can create a PASSWORDs table, each row contains a password and the date it was replaced. The one without a replacement date is the current one.
Of course, you should not be storing plaintext passwords in the database.
Upvotes: 0
Reputation: 27536
I'm not sure if MySQL can store arrays in a column. You might be better off with a password_history
table, with this structure:
password_history
----------------
password
user_id
sequence_number
password_history_id
password
is, well, the password! user_id
is the ID of the user that this record's password belongs to. sequence_number
tells you which password this is. Start with 0 for the first password, and just increase it everytime they change their password. You could also store the date that the password was created, instead of a sequence number, if you like that more. password_history_id
is just a key column, but you could also not use this, and make the primary key a combination of the other three (and those combinations should always be unique, anyway).
Upvotes: 3