Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 Database Design and Application Architecture
 Design Question About Status and Expire Date

Author  Topic 

hacktothefuture
Starting Member

10 Posts

Posted - 2007-07-23 : 12:26:16
I have a design question that I was hoping you all can help with.

When I normally design a table I always make sure to include a status field. This way I can "delete" a record without actually having to delete it, just update the record to a status which signifies deleted. This ensures my users have an undelete capability as well as safesguarding against the "mad clickers" which click right through the "You are deleting this record..." alerts.

I have been recently adding tables which have temporary records and are meant to expire at a certain date. I have designed these tables to have an expiration date field AND a status field.

My question is this: What is the normal convention relating to these types of records/tables? Should queries using these types of tables query them using the status AND the expiration date? Should you create a job that updates the records status based on the expiration date being passed. Should you use a view that only displays current records based on expiration date?

I just want to make sure Im following standard practice as I design these types of tables.

Thanks for your help!

X002548
Not Just a Number

15586 Posts

Posted - 2007-07-23 : 14:27:13
I would go with the view

where the Status = 'deleted' OR DATDIFF(dd,ExpirationDT,GetDate()) > 0



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-07-23 : 16:00:52
probably better to rewrite it to an AND:

where the Status <> 'deleted' AND ExpirationDT < GetDate()

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2007-07-23 : 17:10:53
quote:
Originally posted by spirit1

probably better to rewrite it to an AND:

where the Status <> 'deleted' AND ExpirationDT < GetDate()

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp



Why?

Then both would have to be true. Can't a row expire without being "deleted"?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

hacktothefuture
Starting Member

10 Posts

Posted - 2007-07-24 : 11:34:25
Awesome! Thanks for your help!
Go to Top of Page
   

- Advertisement -