[Koha] SQL for mass auto-generating barcodes for items

Father Vlasie fv at spots.school
Wed Nov 20 11:01:30 NZDT 2019


Hello everyone!

I wrote an SQL command to generate barcodes for all items in Koha.

I did not find a command like this that was already written so I thought I might publish it on this list in case anyone else might find it useful.

You will need to find your mysql username and password in your /etc/koha/sites/library/koha-conf.xml ("library" is your Koha instance name).

In the commands below replace username with your username, of course, and koha_library with your database name. (You can show all databases in msql by entering: show databases; )

    msql -u username -p
    use koha_library;
    set @bnum = 524580000000;update items set barcode=(@bnum:=@bnum+1) where barcode is not null;

This will set a barcode of 524580000001 for the first book and each subsequent book will be assigned a number that is one higher than the last so the second will be 524580000002 and so on.

I am not sure it is necessary but I also did a zebra reindex afterwards. (Again "library" is your Koha instance name.)

    sudo koha-rebuild-zebra -f -v  library

Thank you,

Father Vlasie

IT Director
St. Photios Orthodox Theological Seminary
510 Collier Way, Etna, CA 96027, U.S.A.

Website: www.spots.school


More information about the Koha mailing list