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)