当我在显示时在tb_penerimaan中插入1条记录时,出现1条记录
MariaDB [sijarvis]> SELECT tb_penerimaan.* , tb_pelanggan.nama FROM tb_penerimaan, tb_pelanggan;
+-------------+------------+----------------+----------------+-----------------+----------+------------+-------------+------+-----------+----------------+-------+------------+-------+
| no_servis | tgl_terima | kode_pelanggan | nama_perangkat | model_perangkat | no_model | keluhan | kelengkapan | dp | status | solusi | harga | presentase | nama |
+-------------+------------+----------------+----------------+-----------------+----------+------------+-------------+------+-----------+----------------+-------+------------+-------+
| SER00000001 | 2019-01-31 | PE000001 | ASUS | X453SA | CVT122 | gsdggfddfg | dfgfgd | 5000 | Di Servis | Belum Diservis | 0 | 15 | Anggi |
+-------------+------------+----------------+----------------+-----------------+----------+------------+-------------+------+-----------+----------------+-------+------------+-------+
并插入更多记录出现
MariaDB [sijarvis]> SELECT tb_penerimaan.* , tb_pelanggan.nama FROM tb_penerimaan, tb_pelanggan;
+-------------+------------+----------------+----------------+-----------------+----------+------------+-------------+--------+-----------+----------------+-------+------------+-------+
| no_servis | tgl_terima | kode_pelanggan | nama_perangkat | model_perangkat | no_model | keluhan | kelengkapan | dp | status | solusi | harga | presentase | nama |
+-------------+------------+----------------+----------------+-----------------+----------+------------+-------------+--------+-----------+----------------+-------+------------+-------+
| SER00000001 | 2019-01-31 | PE000001 | ASUS | X453SA | CVT122 | gsdggfddfg | dfgfgd | 5000 | Di Servis | Belum Diservis | 0 | 15 | Anggi |
| SER00000002 | 2019-02-01 | PE000002 | Sharp | Aquos | 305SH | bootloop | charger | 123000 | Di Servis | Belum Diservis | 0 | 15 | Anggi |
| SER00000001 | 2019-01-31 | PE000001 | ASUS | X453SA | CVT122 | gsdggfddfg | dfgfgd | 5000 | Di Servis | Belum Diservis | 0 | 15 | saya |
| SER00000002 | 2019-02-01 | PE000002 | Sharp | Aquos | 305SH | bootloop | charger | 123000 | Di Servis | Belum Diservis | 0 | 15 | saya |
+-------------+------------+----------------+----------------+-----------------+----------+------------+-------------+--------+-----------+----------------+-------+------------+-------+
当我更新记录时显示错误
MariaDB [sijarvis]> UPDATE tb_penerimaan SET no_servis='SER00000002',tgl_terima='2019-02-01',kode_pelanggan='PE000002',nama_perangkat='Sharp',model_perangkat='Aquos',no_model='305sh',keluhan='bootloop',kelengkapan='charger',status='Di Servis',solusi='Instal RAM',harga='15000',presentase='15';
ERROR 1062 (23000): Duplicate entry 'SER00000002' for key 'PRIMARY'
当tb_penerimaan中有1条记录时,我可以更新该记录。
在tb_penerimaan中有2条或更多记录时,发生错误Duplicate entry 'SER00000002' for key 'PRIMARY'
答案 0 :(得分:0)
在当前的Update语句中,您尝试更新所有行。但这是不可能的,因为no_servis
必须是唯一的。正确的是
UPDATE tb_penerimaan SET tgl_terima='2019-02-01', kode_pelanggan='PE000002', nama_perangkat='Sharp', model_perangkat='Aquos', no_model='305sh', keluhan='bootloop', kelengkapan='charger', status='Di Servis', solusi='Instal RAM', harga='15000', presentase='15'
WHERE no_servis = 'SER00000002';