単一の列テーブル (ID 列) を持つ目的は何ですか? 利用可能な適切なユースケースはありますか?
それは本当に良い習慣ですか?
人々はこれを使って Oracle の SEQUENCE を複製していると思います。基本的に、彼らはシステムで作成するすべてのエンティティに対して単一の一意の識別子が必要なため、次のようなものがあります。
CREATE PROCEDURE dbo.GenerateIdentifier
@Identifier INT OUTPUT
AS
BEGIN
SET NOCOUNT ON;
INSERT dbo.SingleColumnTable DEFAULT VALUES;
SET @Identifier = SCOPE_IDENTITY();
END
GO
新しい連絡先、顧客、注文などを追加するときはいつでも、最初にこのプロシージャを呼び出して、新しい識別子を取得します。次に、システム内の 1 つのエンティティのみが識別子 = 1、または 2 などを持ちます。
第 3 正規形を超えて正規化する場合は、1 つのテーブルに対する複数の多対多の関係を排除したい場合があります。これは、スキーマの例がないと説明するのが難しいですが、試してみます...
1 つのテーブルに対する複数の多対多の関係を排除するには、複数のテーブルに共通の代理 PK を使用する必要があります。(これにより、テーブルごとに 1 つではなく、単一の多対多結合が得られます。) 極端なケースでは、純粋な FK または PK として使用できる他のテーブルへの FK のみを提供する単一の列テーブルになります。単一の列の親から多対多の関係を継承する複数のテーブルと考えてください。これの良いところは、(継承された) FK を使用して接続先の多対多テーブルに結合できるため、単一列テーブルが実際のクエリから除外されることです。
Hmm a table with a single column which is an identity and nothing more - there can not be many uses for that.
One I can think of : If you needed multiple tables to have identity values, but did not want these values to clash with each other, then you could use a centralised table which only had one column (identity) and this was used to produce the numbers.
When migrating from Oracle databases, you need a way to emulate Oracle sequences...Tables with single identity columns is the way to go.
そのテーブルは、すべてのアプリケーション(レガシーを含む)が記録システムとして依存する、企業全体の一意のIDジェネレーターとして機能している可能性があります。
Could be for utility Numbers table in SQL Server < 2005. Check this blog post about it.
Anyway a table with identity column only is normally used to overcome some SQL Server obstacle that's either harder to do otherwise or to slow using other (ie. built-in) methods.
Another use could also be of a boolean nature in that the presence of the key in the single-column pkey table indicates a true predicate evaluation for some business logic.
Meaning that the pkey value in this special table could be a foreign key to another table. Though i'm not sure if that buys anything over a bit flag in that other table.
But it's definitely good practice as a tally or numbers table.