简体   繁体   中英

mysql insert server_id while creating record in table

I have a table in mysql in which records can be created from different servers(servers are configured for master slave replication and server ids of each server has been set to 1, 2, 3 and so on), I wanted to know if there is some way by which I can set the default value of a column to server_id or @@server_id so that I can identify which server has created the record.

I have tried

ALTER TABLE `mytable` 
ADD COLUMN `somecolumn` TINYINT NULL DEFAULT server_id

But the above one is not working.

ALTER TABLE `mytable` 
ADD `somecolumn` TINYINT NULL DEFAULT server_id

try it without ADD COLUMN and just use ADD

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM