Are you asking for this:
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].
[tbl_Budget_FK02]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[tbl_Budget] DROP CONSTRAINT tbl_Budget_FK02
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].
[tbl_Dokument_FK00]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[tbl_Dokument] DROP CONSTRAINT tbl_Dokument_FK00
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].
[tbl_FejlOnske_FK01]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[tbl_FejlOnske] DROP CONSTRAINT tbl_FejlOnske_FK01
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].
[T_tbl_Maskine_ITrig]') and OBJECTPROPERTY(id, N'IsTrigger') = 1)
drop trigger [dbo].[T_tbl_Maskine_ITrig]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].
[T_tbl_Maskine_DTrig]') and OBJECTPROPERTY(id, N'IsTrigger') = 1)
drop trigger [dbo].[T_tbl_Maskine_DTrig]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].
[T_tbl_Maskine_UTrig]') and OBJECTPROPERTY(id, N'IsTrigger') = 1)
drop trigger [dbo].[T_tbl_Maskine_UTrig]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].
[tbl_Maskine]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[tbl_Maskine]
GO
CREATE TABLE [dbo].[tbl_Maskine] (
[MaskineNr] [int] IDENTITY (102753, 1) NOT NULL ,
[MaskineNavn] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[MasType] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Serienr] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[MasRumNr] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[MasBruger] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[MasEjerforhold] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[ProducentNr] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[LeverandorNr] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Indkobspris] [money] NULL ,
[IndkobsDato] [datetime] NULL ,
[MasDriftstatus] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[ServiceDato] [datetime] NULL ,
[SerType] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[MasServStatus] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[MasNaesteService] [datetime] NULL ,
[Kalibrering] [datetime] NULL ,
[NaesteKalibrering] [datetime] NULL ,
[MasAfdnr] [int] NULL ,
[Notes] [text] COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[RelationNr] [int] NULL ,
[SidstChangeBy] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[SidstChangeByDate] [datetime] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
ALTER TABLE [dbo].[tbl_Maskine] ADD
CONSTRAINT [aaaaatbl_Maskine_PK] PRIMARY KEY NONCLUSTERED
(
[MaskineNr]
) ON [PRIMARY]
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE TRIGGER T_tbl_Maskine_ITrig ON dbo.tbl_Maskine FOR INSERT AS
SET NOCOUNT ON
/* * PREVENT INSERTS IF NO MATCHING KEY IN 'tbl_Leverandor' */
IF (SELECT COUNT(*) FROM inserted) !=
(SELECT COUNT(*) FROM tbl_Leverandor, inserted WHERE (tbl_Leverandor.
LeverandorNr = inserted.LeverandorNr))
BEGIN
RAISERROR 44447 'The record can''t be added or changed. Referential
integrity rules require a related record in table ''tbl_Leverandor''.'
ROLLBACK TRANSACTION
END
/* * PREVENT INSERTS IF NO MATCHING KEY IN 'tbl_MasAfdeling' */
IF (SELECT COUNT(*) FROM inserted) !=
(SELECT COUNT(*) FROM tbl_MasAfdeling, inserted WHERE (tbl_MasAfdeling.
MasAfdNr = inserted.MasAfdnr))
BEGIN
RAISERROR 44447 'The record can''t be added or changed. Referential
integrity rules require a related record in table ''tbl_MasAfdeling''.'
ROLLBACK TRANSACTION
END
/* * PREVENT INSERTS IF NO MATCHING KEY IN 'tbl_MasBruger' */
IF (SELECT COUNT(*) FROM inserted) !=
(SELECT COUNT(*) FROM tbl_MasBruger, inserted WHERE (tbl_MasBruger.
MasBruger = inserted.MasBruger))
BEGIN
RAISERROR 44447 'The record can''t be added or changed. Referential
integrity rules require a related record in table ''tbl_MasBruger''.'
ROLLBACK TRANSACTION
END
/* * PREVENT INSERTS IF NO MATCHING KEY IN 'tbl_MasDriftstatus' */
IF (SELECT COUNT(*) FROM inserted) !=
(SELECT COUNT(*) FROM tbl_MasDriftstatus, inserted WHERE
(tbl_MasDriftstatus.MasDriftstatus = inserted.MasDriftstatus))
BEGIN
RAISERROR 44447 'The record can''t be added or changed. Referential
integrity rules require a related record in table ''tbl_MasDriftstatus''.'
ROLLBACK TRANSACTION
END
/* * PREVENT INSERTS IF NO MATCHING KEY IN 'tbl_MasEjerforhold' */
IF (SELECT COUNT(*) FROM inserted) !=
(SELECT COUNT(*) FROM tbl_MasEjerforhold, inserted WHERE
(tbl_MasEjerforhold.MasEjerforhold = inserted.MasEjerforhold))
BEGIN
RAISERROR 44447 'The record can''t be added or changed. Referential
integrity rules require a related record in table ''tbl_MasEjerforhold''.'
ROLLBACK TRANSACTION
END
/* * PREVENT INSERTS IF NO MATCHING KEY IN 'tbl_MasProducent' */
IF (SELECT COUNT(*) FROM inserted) !=
(SELECT COUNT(*) FROM tbl_MasProducent, inserted WHERE (tbl_MasProducent.
ProducentNr = inserted.ProducentNr))
BEGIN
RAISERROR 44447 'The record can''t be added or changed. Referential
integrity rules require a related record in table ''tbl_MasProducent''.'
ROLLBACK TRANSACTION
END
/* * PREVENT INSERTS IF NO MATCHING KEY IN 'tbl_MasRumNr' */
IF (SELECT COUNT(*) FROM inserted) !=
(SELECT COUNT(*) FROM tbl_MasRumNr, inserted WHERE (tbl_MasRumNr.MasRumNr
= inserted.MasRumNr))
BEGIN
RAISERROR 44447 'The record can''t be added or changed. Referential
integrity rules require a related record in table ''tbl_MasRumNr''.'
ROLLBACK TRANSACTION
END
/* * PREVENT INSERTS IF NO MATCHING KEY IN 'tbl_MasServiceStatus' */
IF (SELECT COUNT(*) FROM inserted) !=
(SELECT COUNT(*) FROM tbl_MasServiceStatus, inserted WHERE
(tbl_MasServiceStatus.MasServStatus = inserted.MasServStatus))
BEGIN
RAISERROR 44447 'The record can''t be added or changed. Referential
integrity rules require a related record in table ''tbl_MasServiceStatus''.'
ROLLBACK TRANSACTION
END
/* * PREVENT INSERTS IF NO MATCHING KEY IN 'tbl_MasType' */
IF (SELECT COUNT(*) FROM inserted) !=
(SELECT COUNT(*) FROM tbl_MasType, inserted WHERE (tbl_MasType.MasType =
inserted.MasType))
BEGIN
RAISERROR 44447 'The record can''t be added or changed. Referential
integrity rules require a related record in table ''tbl_MasType''.'
ROLLBACK TRANSACTION
END
/* * PREVENT INSERTS IF NO MATCHING KEY IN 'tbl_ServiceType' */
IF (SELECT COUNT(*) FROM inserted) !=
(SELECT COUNT(*) FROM tbl_ServiceType, inserted WHERE (tbl_ServiceType.
SerType = inserted.SerType))
BEGIN
RAISERROR 44447 'The record can''t be added or changed. Referential
integrity rules require a related record in table ''tbl_ServiceType''.'
ROLLBACK TRANSACTION
END
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE TRIGGER T_tbl_Maskine_DTrig ON dbo.tbl_Maskine FOR DELETE AS
SET NOCOUNT ON
/* * PREVENT DELETES IF DEPENDENT RECORDS IN 'tbl_Budget' */
IF (SELECT COUNT(*) FROM deleted, tbl_Budget WHERE (deleted.MaskineNr =
tbl_Budget.MaskineNr)) > 0
BEGIN
RAISERROR 44445 'The record can''t be deleted or changed. Since
related records exist in table ''tbl_Budget'', referential integrity rules
would be violated.'
ROLLBACK TRANSACTION
END
/* * PREVENT DELETES IF DEPENDENT RECORDS IN 'tbl_Dokument' */
IF (SELECT COUNT(*) FROM deleted, tbl_Dokument WHERE (deleted.MaskineNr =
tbl_Dokument.MaskineNr)) > 0
BEGIN
RAISERROR 44445 'The record can''t be deleted or changed. Since
related records exist in table ''tbl_Dokument'', referential integrity rules
would be violated.'
ROLLBACK TRANSACTION
END
/* * PREVENT DELETES IF DEPENDENT RECORDS IN 'tbl_FejlOnske' */
IF (SELECT COUNT(*) FROM deleted, tbl_FejlOnske WHERE (deleted.MaskineNr =
tbl_FejlOnske.MaskineNr)) > 0
BEGIN
RAISERROR 44445 'The record can''t be deleted or changed. Since
related records exist in table ''tbl_FejlOnske'', referential integrity rules
would be violated.'
ROLLBACK TRANSACTION
END
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE TRIGGER T_tbl_Maskine_UTrig ON dbo.tbl_Maskine FOR UPDATE AS
SET NOCOUNT ON
/* * PREVENT UPDATES IF NO MATCHING KEY IN 'tbl_Leverandor' */
IF UPDATE(LeverandorNr)
BEGIN
IF (SELECT COUNT(*) FROM inserted) !=
(SELECT COUNT(*) FROM tbl_Leverandor, inserted WHERE
(tbl_Leverandor.LeverandorNr = inserted.LeverandorNr))
BEGIN
RAISERROR 44446 'The record can''t be added or changed.
Referential integrity rules require a related record in table
''tbl_Leverandor''.'
ROLLBACK TRANSACTION
END
END
/* * PREVENT UPDATES IF NO MATCHING KEY IN 'tbl_MasAfdeling' */
IF UPDATE(MasAfdnr)
BEGIN
IF (SELECT COUNT(*) FROM inserted) !=
(SELECT COUNT(*) FROM tbl_MasAfdeling, inserted WHERE
(tbl_MasAfdeling.MasAfdNr = inserted.MasAfdnr))
BEGIN
RAISERROR 44446 'The record can''t be added or changed.
Referential integrity rules require a related record in table
''tbl_MasAfdeling''.'
ROLLBACK TRANSACTION
END
END
/* * PREVENT UPDATES IF NO MATCHING KEY IN 'tbl_MasBruger' */
IF UPDATE(MasBruger)
BEGIN
IF (SELECT COUNT(*) FROM inserted) !=
(SELECT COUNT(*) FROM tbl_MasBruger, inserted WHERE (tbl_MasBruger.
MasBruger = inserted.MasBruger))
BEGIN
RAISERROR 44446 'The record can''t be added or changed.
Referential integrity rules require a related record in table
''tbl_MasBruger''.'
ROLLBACK TRANSACTION
END
END
/* * PREVENT UPDATES IF NO MATCHING KEY IN 'tbl_MasDriftstatus' */
IF UPDATE(MasDriftstatus)
BEGIN
IF (SELECT COUNT(*) FROM inserted) !=
(SELECT COUNT(*) FROM tbl_MasDriftstatus, inserted WHERE
(tbl_MasDriftstatus.MasDriftstatus = inserted.MasDriftstatus))
BEGIN
RAISERROR 44446 'The record can''t be added or changed.
Referential integrity rules require a related record in table
''tbl_MasDriftstatus''.'
ROLLBACK TRANSACTION
END
END
/* * PREVENT UPDATES IF NO MATCHING KEY IN 'tbl_MasEjerforhold' */
IF UPDATE(MasEjerforhold)
BEGIN
IF (SELECT COUNT(*) FROM inserted) !=
(SELECT COUNT(*) FROM tbl_MasEjerforhold, inserted WHERE
(tbl_MasEjerforhold.MasEjerforhold = inserted.MasEjerforhold))
BEGIN
RAISERROR 44446 'The record can''t be added or changed.
Referential integrity rules require a related record in table
''tbl_MasEjerforhold''.'
ROLLBACK TRANSACTION
END
END
/* * PREVENT UPDATES IF DEPENDENT RECORDS IN 'tbl_Budget' */
IF UPDATE(MaskineNr)
BEGIN
IF (SELECT COUNT(*) FROM deleted, tbl_Budget WHERE (deleted.MaskineNr
= tbl_Budget.MaskineNr)) > 0
BEGIN
RAISERROR 44446 'The record can''t be deleted or changed.
Since related records exist in table ''tbl_Budget'', referential integrity
rules would be violated.'
ROLLBACK TRANSACTION
END
END
/* * PREVENT UPDATES IF DEPENDENT RECORDS IN 'tbl_Dokument' */
IF UPDATE(MaskineNr)
BEGIN
IF (SELECT COUNT(*) FROM deleted, tbl_Dokument WHERE (deleted.
MaskineNr = tbl_Dokument.MaskineNr)) > 0
BEGIN
RAISERROR 44446 'The record can''t be deleted or changed.
Since related records exist in table ''tbl_Dokument'', referential integrity
rules would be violated.'
ROLLBACK TRANSACTION
END
END
/* * PREVENT UPDATES IF DEPENDENT RECORDS IN 'tbl_FejlOnske' */
IF UPDATE(MaskineNr)
BEGIN
IF (SELECT COUNT(*) FROM deleted, tbl_FejlOnske WHERE (deleted.
MaskineNr = tbl_FejlOnske.MaskineNr)) > 0
BEGIN
RAISERROR 44446 'The record can''t be deleted or changed.
Since related records exist in table ''tbl_FejlOnske'', referential integrity
rules would be violated.'
ROLLBACK TRANSACTION
END
END
/* * PREVENT UPDATES IF NO MATCHING KEY IN 'tbl_MasProducent' */
IF UPDATE(ProducentNr)
BEGIN
IF (SELECT COUNT(*) FROM inserted) !=
(SELECT COUNT(*) FROM tbl_MasProducent, inserted WHERE
(tbl_MasProducent.ProducentNr = inserted.ProducentNr))
BEGIN
RAISERROR 44446 'The record can''t be added or changed.
Referential integrity rules require a related record in table
''tbl_MasProducent''.'
ROLLBACK TRANSACTION
END
END
/* * PREVENT UPDATES IF NO MATCHING KEY IN 'tbl_MasRumNr' */
IF UPDATE(MasRumNr)
BEGIN
IF (SELECT COUNT(*) FROM inserted) !=
(SELECT COUNT(*) FROM tbl_MasRumNr, inserted WHERE (tbl_MasRumNr.
MasRumNr = inserted.MasRumNr))
BEGIN
RAISERROR 44446 'The record can''t be added or changed.
Referential integrity rules require a related record in table
''tbl_MasRumNr''.'
ROLLBACK TRANSACTION
END
END
/* * PREVENT UPDATES IF NO MATCHING KEY IN 'tbl_MasServiceStatus' */
IF UPDATE(MasServStatus)
BEGIN
IF (SELECT COUNT(*) FROM inserted) !=
(SELECT COUNT(*) FROM tbl_MasServiceStatus, inserted WHERE
(tbl_MasServiceStatus.MasServStatus = inserted.MasServStatus))
BEGIN
RAISERROR 44446 'The record can''t be added or changed.
Referential integrity rules require a related record in table
''tbl_MasServiceStatus''.'
ROLLBACK TRANSACTION
END
END
/* * PREVENT UPDATES IF NO MATCHING KEY IN 'tbl_MasType' */
IF UPDATE(MasType)
BEGIN
IF (SELECT COUNT(*) FROM inserted) !=
(SELECT COUNT(*) FROM tbl_MasType, inserted WHERE (tbl_MasType.
MasType = inserted.MasType))
BEGIN
RAISERROR 44446 'The record can''t be added or changed.
Referential integrity rules require a related record in table ''tbl_MasType''.
'
ROLLBACK TRANSACTION
END
END
/* * PREVENT UPDATES IF NO MATCHING KEY IN 'tbl_ServiceType' */
IF UPDATE(SerType)
BEGIN
IF (SELECT COUNT(*) FROM inserted) !=
(SELECT COUNT(*) FROM tbl_ServiceType, inserted WHERE
(tbl_ServiceType.SerType = inserted.SerType))
BEGIN
RAISERROR 44446 'The record can''t be added or changed.
Referential integrity rules require a related record in table
''tbl_ServiceType''.'
ROLLBACK TRANSACTION
END
END
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
Hi
Sorry because of my late replay but I can only work with the SQL server when
I am at work.
“SQL Profiler†where do I find that?
[quoted text clipped - 10 lines]