DEV Community

Dimitrios Desyllas
Dimitrios Desyllas

Posted on

How I limit further the foreign key in my database?

I try to make a self-referencing table as discussed upon:
https://dba.stackexchange.com/q/334728/118215

In order words I have a table:

CREATE TABLE mydb.dbo.files (
    id bigint IDENTITY(1,1) NOT NULL,
    name nvarchar(255) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
    folder bigint NULL,
    [type] nvarchar(10) NOT NULL CHECK ([type] IN('FILE','FOLDER')) DEFAULT 'FOLDER'
    CONSTRAINT PK__category__3213E83FDB19A582 PRIMARY KEY (id),
    CONSTRAINT folder_fk FOREIGN KEY (folder) REFERENCES delta.dbo.files(id)
);

Enter fullscreen mode Exit fullscreen mode

And I want the record referenced upon folder to be one having type FOLDER is this feasible?

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay