java - How to guess or determine a SQL identity field and avoid duplicate -
i trying avoid duplicate updates data, know if there way update 1 row field without updating piece of data in subsequent row. here scenario, have code:
string sql = "update vagas set matricula ='" +txtmat.gettext() + "' curso ='" +combocurso.getselecteditem().tostring() + "' , turma='"+turmacombo.getselecteditem().tostring()+"'"; pstmt = conlogin.preparestatement(sql); pstmt.execute(); joptionpane.showmessagedialog(null, "vagas atualizados com sucesso!");
i want update field matricula
(which means student subscription id), course (curso
) equals combocurso.getselecteditem().tostring()
combobox , turma
(which means course classroom filled group) equals combocurso.getselecteditem().tostring()
combobox.
everything updates ok except 1 issue, example have matricula
rows same name (1acc
) represents 2 classroom vacancies. when call update fill both of them matricula
number not desired since want fill 1 vacancy, both have same names fill both.
so there first field(column) named vagas
(not table name column name) int identity (1,1)
field, , want fill 1 field when call update command. trying comparing vagas
column cant seem find way it.
if have multiple records meet criteria, , want 1 of records updated, have insufficient criteria update. isn't code problem, it's design problem... need choose how wish pick 1 record update out of many records selecting. how want pick record update?
if answer doesn't matter, use aggregate function on identity column constraint, example:
where ... , vagas = (select min(vagas) vagas ...)
note "..." represents conditions you're using. snippet of code picks vagas record lowest vagas value (via select subquery).
Comments
Post a Comment