Reputation: 1135
I just was wondering if is it possible to associate an user to the data inserted in a table.
For example:
I have a table Customers
with columns customerID
, name
and address
. Is there any method in MySql to know what user has inserted each row in the table or must I add a column userID
in the table Customer to add the user in my SQL Insert statement?.
If I have only one table, it is not a proble to add the userID
column. But when i have multiple tables, maybe it becomes a messy task.
Thanx in advance.
Upvotes: 0
Views: 58
Reputation: 77876
If you are trying to find out the user_id
caused the insert then NO, there is no other way than you storing it explicitly likewise you already have thought of.
If there is multiple tables for which you want to store the same information; then you can probably have a separate table where you can have the user_id
column and can use a AFTER INSERT TRIGGER
to insert the user id in this table.
Upvotes: 1
Reputation: 1594
No, no such functionality is provided by MySQL. You'll have to add a column for user_id in your table(s) and insert the user id yourself.
Upvotes: 1