Implementing one-to-zero-or-one relation in SQL Server

The 1-0..1 relation in your database is directly visible. It is built between Course and OnlineCourse tables where Course is principal in relation (1) and OnlineCourse is dependent with FK configured on CourseID. FK is also PK of the OnlineCourse = it must be unique and because of that it is 0..1. Database “always” uses … Read more

Cannot delete rows from a temporal history table

If you make the DELETE dynamic, your stored procedure will successfully ALTER the table, DELETE the records in question, and then ALTER it back. CREATE PROCEDURE [dbo].[OrderHistoryDelete] (@Id UNIQUEIDENTIFIER) AS BEGIN DECLARE @sql VARCHAR(MAX) BEGIN TRANSACTION ALTER TABLE [dbo].[Order] SET ( SYSTEM_VERSIONING = OFF ) SET @sql=”DELETE FROM [dbo].[OrderHistory] WITH (TABLOCKX) WHERE [Id] = “” … Read more