Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I don't know what the context of your scenario is, but it might be worth looking into using a more pre-fabiracted method to generate your unique tokens (Unique ID on the table for instancE?)</p> <p>That being said, if you want the fine-tuning control over the format of your token, it might be worth looking into wrapping the uniqueness-generation routine into SQL procedure, so that the determination is made in one transaction, rather than kicing off a separate communication request for every iteration.</p> <p>Something like this generates 1000 "unique" tokens, but it could be easily adjusted to loop until the code is truly unique rather than a fixed number of loops (and it can probably be cleaned up a bit :) ):</p> <pre><code>DECLARE @token as varchar(6), @numberOfLoops int, @currentLoop int, @pool varchar(50) -- Initialize SET @token = '' SET @numberOfLoops = 1000 SET @currentLoop = 0 SET @pool = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890'; WHILE (@currentLoop &lt; @numberOfLoops) BEGIN SET @token = SUBSTRING(@pool, CAST((RAND() * LEN(@pool) + 1) as int), 1) + SUBSTRING(@pool, CAST((RAND() * LEN(@pool) + 1) as int), 1) + SUBSTRING(@pool, CAST((RAND() * LEN(@pool) + 1) as int), 1) + SUBSTRING(@pool, CAST((RAND() * LEN(@pool) + 1) as int), 1) + SUBSTRING(@pool, CAST((RAND() * LEN(@pool) + 1) as int), 1) + SUBSTRING(@pool, CAST((RAND() * LEN(@pool) + 1) as int), 1); print @token; SET @currentLoop = @currentLoop + 1; END </code></pre> <p>There are some major caveats to consider here, though. The biggest concern I can think of with tokens you roll yourself is the problem of temporary uniqueness. Depending on when you're assigning the token, it may be unique w/r/t your data source one moment, but then --- potentially -- claimed the next if you're not careful.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload