Click here to Skip to main content
15,902,835 members
Home / Discussions / Database
   

Database

 
GeneralRe: To get the current value for SORT_IN_TEMPDB Pin
Arun Abraham Jose30-Jan-09 0:33
Arun Abraham Jose30-Jan-09 0:33 
GeneralRe: To get the current value for SORT_IN_TEMPDB Pin
Wendelius30-Jan-09 7:27
mentorWendelius30-Jan-09 7:27 
GeneralAutoincrement per field Pin
Mustafa Ismail Mustafa27-Jan-09 18:56
Mustafa Ismail Mustafa27-Jan-09 18:56 
GeneralRe: Autoincrement per field Pin
Wendelius27-Jan-09 19:35
mentorWendelius27-Jan-09 19:35 
GeneralRe: Autoincrement per field Pin
Mustafa Ismail Mustafa27-Jan-09 20:51
Mustafa Ismail Mustafa27-Jan-09 20:51 
GeneralRe: Autoincrement per field Pin
Wendelius27-Jan-09 20:53
mentorWendelius27-Jan-09 20:53 
GeneralRe: Autoincrement per field [edit] [modified] Pin
Mustafa Ismail Mustafa27-Jan-09 21:15
Mustafa Ismail Mustafa27-Jan-09 21:15 
GeneralRe: Autoincrement per field Pin
Wendelius27-Jan-09 21:49
mentorWendelius27-Jan-09 21:49 
Mustafa Ismail Mustafa wrote:
the primary key would be the combined PatientID and the AdmittanceID, this shouldn't affect the implementation


Actually it does. If it's defined as primary key, you cannot leave it null in the insert statement. Also you cannot insert duplicates. One way could be that you use negative patientid in the insert statement and this trigger modifies the values to correct ones. In that case the where clause would be something like:
...
WHERE  (AdmittanceId, PatientId) = (@OldAdmittanceId, @PatientId);


Also it would be benefitial to have a surrogate key if none is present at the moment. That would make this operations easier. You could change the current primary key to unique key and define the surrogate key as primary key.

Mustafa Ismail Mustafa wrote:
Also, why do I need the cursor


I didn't quickly have any other idea. The problem is that the trigger fires only once when rows are added regardless how many rows are added by the same statement. In other words the trigger isn't executed separately for each inserted row. Now if you add simultaneously two rows for the same patientid and you simply execute an update which sets the patientid to current max in db + 1 those two rows would have the same value for the patientid.

Mustafa Ismail Mustafa wrote:
There shouldn't be gaps because the values increment for each patient


Ok, but what I meant is that is it ok to delete a record later? If it is, I think you would have a gap in patientid numbering. Don't know if it's any problem though.

The need to optimize rises from a bad design.My articles[^]

GeneralRe: Autoincrement per field Pin
Mustafa Ismail Mustafa28-Jan-09 1:16
Mustafa Ismail Mustafa28-Jan-09 1:16 
GeneralRe: Autoincrement per field Pin
Wendelius28-Jan-09 1:24
mentorWendelius28-Jan-09 1:24 
GeneralRe: Autoincrement per field Pin
Mustafa Ismail Mustafa28-Jan-09 1:28
Mustafa Ismail Mustafa28-Jan-09 1:28 
GeneralRe: Autoincrement per field Pin
Wendelius28-Jan-09 1:43
mentorWendelius28-Jan-09 1:43 
Questionhow the oracle packages are implemeted in the sql server Pin
lakshmichawala27-Jan-09 17:33
lakshmichawala27-Jan-09 17:33 
AnswerRe: how the oracle packages are implemeted in the sql server Pin
Wendelius27-Jan-09 19:44
mentorWendelius27-Jan-09 19:44 
GeneralRe: how the oracle packages are implemeted in the sql server Pin
lakshmichawala27-Jan-09 20:21
lakshmichawala27-Jan-09 20:21 
GeneralRe: how the oracle packages are implemeted in the sql server Pin
Wendelius27-Jan-09 20:33
mentorWendelius27-Jan-09 20:33 
QuestionSimultaneous access to MS Access Pin
Member 382292227-Jan-09 12:20
Member 382292227-Jan-09 12:20 
AnswerRe: Simultaneous access to MS Access Pin
Wendelius27-Jan-09 12:46
mentorWendelius27-Jan-09 12:46 
GeneralRe: Simultaneous access to MS Access Pin
Member 38229225-Feb-09 13:48
Member 38229225-Feb-09 13:48 
AnswerRe: Simultaneous access to MS Access Pin
PIEBALDconsult27-Jan-09 15:13
mvePIEBALDconsult27-Jan-09 15:13 
GeneralRe: Simultaneous access to MS Access Pin
Member 38229225-Feb-09 13:50
Member 38229225-Feb-09 13:50 
GeneralRe: Simultaneous access to MS Access Pin
PIEBALDconsult5-Feb-09 14:11
mvePIEBALDconsult5-Feb-09 14:11 
GeneralRe: Simultaneous access to MS Access Pin
Member 38229225-Feb-09 14:32
Member 38229225-Feb-09 14:32 
QuestionGetting values from two tables. Pin
kurangu27-Jan-09 6:40
kurangu27-Jan-09 6:40 
AnswerRe: Getting values from two tables. Pin
Wendelius27-Jan-09 6:58
mentorWendelius27-Jan-09 6:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.