Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Could anyone suggest why UNIQUE constraint doesn't work in the warehouse?
I expected that creating PRIMARY KEY will be enough to not all duplication but the duplication is allowed even if I created both
CREATE TABLE [dev].[Calendar]
(
[Year] INT NOT NULL
);
ALTER TABLE [dev].[Calendar] ADD CONSTRAINT PK_Calendar_1 PRIMARY KEY NONCLUSTERED ([Year]) NOT ENFORCED;
ALTER TABLE [dev].[Calendar] ADD CONSTRAINT UK_Calendar_ UNIQUE NONCLUSTERED ([Year]) NOT ENFORCED;
INSERT INTO [dev].[Calendar] ([Year]) VALUES (2020);
INSERT INTO [dev].[Calendar] ([Year]) VALUES (2020);
INSERT INTO [dev].[Calendar] ([Year]) VALUES (2020);
INSERT INTO [dev].[Calendar] ([Year]) VALUES (2020);
SELECT * FROM [dev].[Calendar]
Solved! Go to Solution.
You would need to build in de-duplicating in your loading processes. Think of Fabric SQL like Databricks, Snowflake etc, none of these services have enforcable unique/foreign key constraints.
Unique and Foreign Key contraints are used by the Fabric SQL engine for optimisation purposes. E.G if you define a column as unique and you use that column in a filter or join, once the SQL engine finds that value it knows it won't occur again (as an example).
So you won't use these contraints in the way you would with SQL Server.
-------------------------------------------------
If my post has been useful please consider
providing Kudos or marking as the Solution
-------------------------------------------------
Hi @Marusyk constraints are not actually enforced in Fabric Warehouses, hence the NOT ENFORCED keyword is required. This is a limitation of scale out sql services like Fabric SQL. These constraints are more for engine optimisation
so how to deny duplication then?
do you mean unique constraints mean nothing to me as a database admin?
If they only for the engine how can we use it?
You would need to build in de-duplicating in your loading processes. Think of Fabric SQL like Databricks, Snowflake etc, none of these services have enforcable unique/foreign key constraints.
Unique and Foreign Key contraints are used by the Fabric SQL engine for optimisation purposes. E.G if you define a column as unique and you use that column in a filter or join, once the SQL engine finds that value it knows it won't occur again (as an example).
So you won't use these contraints in the way you would with SQL Server.
-------------------------------------------------
If my post has been useful please consider
providing Kudos or marking as the Solution
-------------------------------------------------
Check out the April 2024 Fabric update to learn about new features.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
User | Count |
---|---|
10 | |
10 | |
8 | |
5 | |
4 |