xo / usql

Universal command-line interface for SQL databases
MIT License
8.81k stars 346 forks source link

No foreign keys displayed on sql server #440

Open birkmose opened 4 months ago

birkmose commented 4 months ago

Given example DDL:

create table Test  (
        Id         uniqueidentifier not null primary key
)
go

create table TestRef  (
        Id         uniqueidentifier not null primary key
                   constraint FK_TestRef_Test_Id references Test,
)
go

I try to display TestRef - but do not observe the FK_TestRef_Test_Id as expected:

\d TestRef
           BASE TABLE "dbo.TestRef"
 Name |       Type       | Nullable | Default 
------+------------------+----------+---------
 Id   | uniqueidentifier | "NO"     |  
Indexes:
  "PK__TestRef__3214EC07AEDAFDCF" PRIMARY_KEY, UNIQUE, CLUSTERED (Id)

/* Would have  expected the foreign key to have been displayed here */
kenshaw commented 4 months ago

For reference:

pg:postgres@=> \d testref
      table "public.testref"
 Name | Type | Nullable | Default 
------+------+----------+---------
 id   | uuid | "NO"     |  
Indexes:
  "testref_pkey" PRIMARY_KEY, UNIQUE, btree (id)
Foreign-key constraints:
  "fk_testref_test_id" FOREIGN KEY (id) REFERENCES test(id) ON UPDATE NO ACTION ON DELETE NO ACTION

pg:postgres@=> 
$ psql postgres://postgres:P4ssw0rd@localhost
psql (16.1)
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, compression: off)
Type "help" for help.

postgres=# \d testref
             Table "public.testref"
 Column | Type | Collation | Nullable | Default 
--------+------+-----------+----------+---------
 id     | uuid |           | not null | 
Indexes:
    "testref_pkey" PRIMARY KEY, btree (id)
Foreign-key constraints:
    "fk_testref_test_id" FOREIGN KEY (id) REFERENCES test(id)

postgres=#