Hello. There is a table in the database

[dbo].[Query]( [Num] [int] NOT NULL, [Client] [int] NULL, [doer] [int] NULL, [DateOfQuery] [datetime] NULL, [Dwell] [int] NULL, 

I need to create a trigger so that when adding a new record the date is not more than the current one. I had a problem with setting the limit. Just starting to learn SQL

    2 answers 2

    Well, if you just need a trigger, then you can create it using the following construction:

     create trigger trigger_name on table_name instead of insert as --тут собственно и выполняете --все необходимые операции 

      You do not need a trigger, just add constraint:

       CREATE TABLE [dbo].[Query]( [Num] [int] NOT NULL, [Client] [int] NULL, [doer] [int] NULL, [DateOfQuery] [datetime] NULL CHECK ([DateOfQuery] <= GetDate()), [Dwell] [int] NULL) 
      • Thank you, I will consider it. But unfortunately I need exactly the trigger. - andreich
      • What is the need for a trigger? - minamoto