Using a single column table (Identity)?

Why do I need one column table (identity column)? Is there a good use case?

Is this really good practice?

+3
source share
7 answers

I think people use this for Oracle SEQUENCE replication. Basically, they want to have a unique unique identifier for any object that they create on their system, so they have something like this:

CREATE PROCEDURE dbo.GenerateIdentifier
    @Identifier INT OUTPUT
AS
BEGIN
    SET NOCOUNT ON;

    INSERT dbo.SingleColumnTable DEFAULT VALUES;

    SET @Identifier = SCOPE_IDENTITY();
END
GO

Now, when they want to add a new contact or customer or order, etc., they first call this procedure and get a new identifier. Then only one object in the system will have identifier = 1 or 2, etc.

+5

3- , "-" . , ...

"-" , , . ( -- .) , , FK, , FK PK. , , . , , () FK , .

+4

Hmm , - .

, : , , , , , (), .

+2

Oracle Oracle... - .

+2

, ( ) .

+2

SQL Server < 2005. .

SQL Server, , (.. ) .

+1

, -.

, pkey . , - .

But this is definitely good practice as a table with tables or numbers.

+1
source

Source: https://habr.com/ru/post/1720794/


All Articles