Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Update and Set in one statement?
Message
De
01/12/2014 09:37:38
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2014
Application:
Web
Divers
Thread ID:
01611535
Message ID:
01611598
Vues:
46
>When you feel 100% (I wish you do get 100% well, regardless of my question) and if you have a moment, could you, please, educate me on what is "factory sequence object"? Even if only in a few words. TIA.

For years, database people have wanted something along the lines of a table-independent identity value, that's unique across all rows in ALL tables of a database (as opposed to a normal identity that's only capable of being unique within a single table)

So imagine if you have a Prodmaster, CustMaster, and GLmaster.

The unique value for the identity keys for the first three rows in Prodmaster would be 1,4, 7......for the Custmaster, 2, 5, 8....and for GLMaster, 3, 6, 9

So when a row is appended, the integer key would be unique across all tables in the database, not just the single table.

You can do this with a uniqueidentifier datatype and either the functions new() or newsequentialid() and it will work - but a uniqueidentifier is 32 characters and 16 bytes....but many would prefer cross table uniqueness with a four byte integer (which compresses better) than a 16 byte alphanumeric.

So DBAs would set up a special stored procedure with a one row, one column control table that held the next INT to be used. The proc would use the same type of logic being discussed in this thread - updating the control table with the next value (usually one) and assigning it to a variable in the same line of code (and using the necessary locks). Someone here on the UT the code for it has been posted many times. Some call it a factory because it's spitting out the next value to be used, and a sequence object because it's generating the next numerical sequence from this one row, one column control table that holds the next value to be used.

Now, enter SQL 2012. SQL 2012 has a new sequence object built into the database engine. So you can use it to get table-independent identity values, and you don't need to use a special stored procedure of your own anymore.

Hope that helps.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform