Getting milliseconds on a time stamp

I would like millisecond resolution. As for accuracy...I am OK with the accuracy being off 1/10th of a second or more. I want as much accuracy as the Yun can muster. I am using the time value as a key in a database. THe database cannot use identical keys. If you enter a new value with an identical key then the database will update the existing record with the new data. So:

I am looking to get a time stamp as close as reasonably possible
A Unique number as a key