home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / database / sybase / 651 < prev    next >
Encoding:
Text File  |  1993-01-11  |  2.2 KB  |  63 lines

  1. Newsgroups: comp.databases.sybase
  2. Path: sparky!uunet!tekbspa!tssgate!esh
  3. From: esh@prague.tss.com (Edward S. Hirgelt)
  4. Subject: Re: Questions sbout time based queries
  5. In-Reply-To: jimj@meaddata.com's message of 8 Jan 1993 21:54:22 GMT
  6. Message-ID: <ESH.93Jan11095641@prague.tss.com>
  7. Sender: news@tss.com (USENET Network News)
  8. Organization: Teknekron Software Systems, Inc.
  9. References: <1ikt6eINNh61@meaddata.meaddata.com>
  10. Distribution: na
  11. Date: Mon, 11 Jan 1993 17:56:41 GMT
  12. Lines: 49
  13.  
  14.  
  15. On 8 Jan 1993 21:54:22 GMT,
  16. jimj@meaddata.com (Jim Johnstone) said:
  17.  
  18.  
  19.  
  20. Jim> We have a need to query out all rows entered by a given user since
  21. Jim> a specified time.  My first thought was to use timestamp columns in
  22. Jim> all tables. So (I am very new to Sybase, so please be nice) my
  23. Jim> questions are:
  24.  
  25. Jim> 1. Are timestamps the best way to go? 
  26. Jim> (nice because they are automatic, bad because they can't be
  27. Jim> CONVERTed)
  28.  
  29. Depending on what you haven't said about your requirements, I probably
  30. wouldn't use timestamps. They do get changed when someone updates the
  31. row. This may or may not be the same person who did the insert. You may
  32. or may not care. Also rows bcp'd in do not appear to get their
  33. timestamps set. Or rather, timestamps columns seme to be set to 0. 
  34.  
  35. I tend to use timestamps to notice when someone updated a row out from
  36. under a browse rather than for anything else. Perhaps this is too narrow
  37. a view for timestamps. My solution follows below:
  38.  
  39. Jim> 2. Should I just use datetime in each table?
  40. Jim> ... insert TABLE values(..., getdate(), ...) 
  41. Jim> then 
  42. Jim> ... select * from TABLE where date > @threshold and user = @user
  43.  
  44. This is what I would do. However I would define a trigger that
  45. automatically set the date field to the current date when the row is
  46. inserted. This ensures that no one can subvert the dating mechanism. You
  47. also get to decide what to do on updates. 
  48.  
  49. Your select above works nicely.
  50.  
  51. Jim> 3. Is there some Sybase table/feature that will allow me to meet the 
  52. Jim> requirement directly?
  53.  
  54. See above -- triggers.
  55.  
  56. Hope this helps.
  57.  
  58. Ed
  59. --
  60. Ex vitio alterius    |Ed Hirgelt            |esh@tss.com
  61. sapiens emendat suum.    |Teknekron Software Systems, Inc|
  62. (Publilius Syrus)    |Palo Alto, Ca.            |
  63.