At 10:23 AM 11/29/01 -0500, Jeff Johnson wrote:
>The other problem is that SQL Server doesn't have Sequences.  Hal Helms,
>a CF guru, writes that to overcome this, just use GetUUID() to create
>primary keys that are almost guaranteed to be unique across the entire
>world.  The downside is that those primary keys are 35 bytes long.
>Yuck.  I'm curious how others simulate sequences on MS SQL Server and
>similar databases.  Server side locking of tables during inserts?

I'm not sure what Sequences are, but SQL Server most definitely does 
support unique primary keys -- just make sure Identity is turned on for the 
primary key column.  Then you can insert a new row and retrieve its 
auto-generated unique primary key with something like this:

SET NOCOUNT ON
INSERT INTO MyTable (MyValue1, MyValue2) VALUES ('foo', 'bar')
SELECT @@IDENTITY AS NewPrimaryKey
SET NOCOUNT OFF

In other words, @@IDENTITY is the last Identity value that was 
auto-generated on the given connection.

The business with "SET NOCOUNT ON" and "SET NOCOUNT OFF" is needed due to a 
bug that I read about in the Microsoft Knowledge Base.


--

- Geoff Talvola
   [EMAIL PROTECTED]

_______________________________________________
Webware-discuss mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/webware-discuss

Reply via email to