cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

How can I check that column on a delta table has a "NOT NULL" constraint or not?

Lon_Fortes
Databricks Partner

Title pretty much says it all -

I'm trying to determine whether or not a column on my existing delta table was defined as NOT NULL or not. It does not show up in any of the metadata (describe detail, describe history, show tblproperties).

Thanks in advance

1 ACCEPTED SOLUTION

Accepted Solutions

Lon_Fortes
Databricks Partner

I've found a solution, the following scala serves my needs:

val table = spark.table("<database>.<tablename>")

val schema = table.printSchema

View solution in original post

4 REPLIES 4

Lon_Fortes
Databricks Partner

I've found a solution, the following scala serves my needs:

val table = spark.table("<database>.<tablename>")

val schema = table.printSchema

Matthew8
New Contributor II

walgreenslistens Wrote:

A UNIQUE constraint defines a set of columns that uniquely identify rows in a table only if all the key values are not NULL. If one or more key parts are NULL, duplicate keys are allowed.

muki
New Contributor II

if using python, we can use

display(spark.catalog.listColumns('<catalog>.<schema>.<table>'))

iyashk-DB
Databricks Employee
Databricks Employee

@muki , you can run 
SHOW CREATE TABLE <catalog>.<schema>.<table>

and in that also you can also see the constraints applied.