Date as primary key?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Vbbeginner07
    New Member
    • Dec 2007
    • 103

    #16
    Originally posted by debasisdas
    have you tried using count() ?
    yes,but have some errors while debugging...... ..

    Comment

    • Vbbeginner07
      New Member
      • Dec 2007
      • 103

      #17
      Originally posted by debasisdas
      have you tried using count() ?
      But have to check the dates being inserted while we are saving it...
      now it checks the id,but have to check the date also....

      Comment

      • vikas000000a
        New Member
        • Jan 2008
        • 46

        #18
        What's the problem with error trapping method?

        I mean, what message are you getting when using this? I don't find any problem using this method. If you are not using Oracle, then you can have error number for the db (you are using) that is thrown when a unique constraint is violated.

        This has always worked for me without any fault.

        Tell me in detail so I can help you out.

        Comment

        • Vbbeginner07
          New Member
          • Dec 2007
          • 103

          #19
          Originally posted by vikas000000a
          What's the problem with error trapping method?

          I mean, what message are you getting when using this? I don't find any problem using this method. If you are not using Oracle, then you can have error number for the db (you are using) that is thrown when a unique constraint is violated.

          This has always worked for me without any fault.

          Tell me in detail so I can help you out.
          but my questn. is that once an id is saved with one particular date,how can we add another date with the same id???
          I am confused...each time it needs to check id and date,but when id is there,n other date can be saved,rite???t. ,

          Comment

          • debasisdas
            Recognized Expert Expert
            • Dec 2006
            • 8119

            #20
            Originally posted by Vbbeginner07
            but my questn. is that once an id is saved with one particular date,how can we add another date with the same id???
            I am confused...each time it needs to check id and date,but when id is there,n other date can be saved,rite???t. ,
            how can the same employee have the same date entered twice ?

            check using

            [CODE=oracle]select count(*) from table_name where user_id='id' and user_date = 'date'[/CODE]
            before inserting values

            insert only if this returns 0

            also takecare not to use DATE as field name in any table.

            Comment

            • Vbbeginner07
              New Member
              • Dec 2007
              • 103

              #21
              Originally posted by debasisdas
              how can the same employee have the same date entered twice ?
              check using
              [CODE=oracle]select count(*) from table_name where id='id' and date = 'date'[/CODE]
              before inserting values
              insert only if this returns 0
              see to that,one can work for different hours for different dates right???
              As in above replies:
              MII/101 added to database as 02/01/08 with 10 hours
              the same emp.id should be enetered with 8 hours in 03/01/08
              Did u understand???Oe r else explanation needed?

              Comment

              • debasisdas
                Recognized Expert Expert
                • Dec 2006
                • 8119

                #22
                Originally posted by Vbbeginner07
                see to that,one can work for different hours for different dates right???
                As in above replies:
                MII/101 added to database as 02/01/08 with 10 hours
                the same emp.id should be enetered with 8 hours in 03/01/08
                Did u understand???Oe r else explanation needed?
                so what , your date is different or not

                and you are having composit key on id and date , right ?

                Comment

                • Vbbeginner07
                  New Member
                  • Dec 2007
                  • 103

                  #23
                  Originally posted by debasisdas
                  so what , your date is different or not
                  and you are having composit key on id and date , right ?
                  yes,the date is different

                  Comment

                  • debasisdas
                    Recognized Expert Expert
                    • Dec 2006
                    • 8119

                    #24
                    Originally posted by Vbbeginner07
                    yes,the date is different
                    i hope you got that right now .

                    Comment

                    • Vbbeginner07
                      New Member
                      • Dec 2007
                      • 103

                      #25
                      Originally posted by debasisdas
                      i hope you got that right now .
                      yes,but not getting it in prper way.......ny way thanks

                      Comment

                      • debasisdas
                        Recognized Expert Expert
                        • Dec 2006
                        • 8119

                        #26
                        Originally posted by Vbbeginner07
                        yes,but not getting it in prper way.......ny way thanks
                        what is the problem now ?

                        Comment

                        • Killer42
                          Recognized Expert Expert
                          • Oct 2006
                          • 8429

                          #27
                          If the primary key is made up of the ID and date fields, then any attempt to store a record which duplicates both of these fields must produce some sort of error (unless your database allows duplicate primary keys, which seems rather odd). Why can't you trap that error and deal with it accordingly?

                          Comment

                          • Vbbeginner07
                            New Member
                            • Dec 2007
                            • 103

                            #28
                            Originally posted by Killer42
                            If the primary key is made up of the ID and date fields, then any attempt to store a record which duplicates both of these fields must produce some sort of error (unless your database allows duplicate primary keys, which seems rather odd). Why can't you trap that error and deal with it accordingly?
                            killer,now im keeeping only date as a primary key...would it help??? sugeest if its not a good idea?
                            but the code count isnt working out,because im selecting date from a datepicker
                            and store date as 12/18/2007
                            anyone please guide me through?

                            Comment

                            • debasisdas
                              Recognized Expert Expert
                              • Dec 2006
                              • 8119

                              #29
                              Kindly post how you are trying to use count that it is not working.
                              Last edited by Killer42; Jan 4 '08, 05:33 AM.

                              Comment

                              • Killer42
                                Recognized Expert Expert
                                • Oct 2006
                                • 8429

                                #30
                                Originally posted by Vbbeginner07
                                killer,now im keeeping only date as a primary key...would it help??? sugeest if its not a good idea?
                                I don't know enough about database design to tell you whether it's a good or a bad idea. I was merely making the point that if your primary key was made up of both fields, then you couldn't create duplicate records even if you tried - the database software would not allow it.

                                Um... in this case, using the date alone as the PK is probably not a good idea. Since the PK must be unique, it means you can only store one record per date. And I don't think this is what you want.

                                Comment

                                Working...