Skip to content

Instantly share code, notes, and snippets.

@zapkub
Created September 8, 2018 06:22
Show Gist options
  • Save zapkub/44006990a962e53a60bcb31c09cf1728 to your computer and use it in GitHub Desktop.
Save zapkub/44006990a962e53a60bcb31c09cf1728 to your computer and use it in GitHub Desktop.
แก้ ตาราง plant ให้เริ่ม id ด้วย 0 ได้
DROP TABLE tb_opr_plant;
CREATE TABLE [dbo].[tb_opr_Plant](
[Plant_ID] [int] IDENTITY(0,1) NOT NULL,
[Quota_ID] [int] NULL,
[Zone_ID] [int] NULL,
[Plant_No] [nvarchar](20) NULL,
[Plant_Name] [nvarchar](100) NULL,
[Plant_Moo] [int] NULL,
[Plant_Province] [nvarchar](150) NULL,
[Plant_District] [nvarchar](150) NULL,
[Plant_SubDistrict] [nvarchar](150) NULL,
[Plant_Latitude] [float] NULL,
[Plant_Longitude] [float] NULL,
[Plant_GeoLocation] [geography] NULL,
[Plant_AreaRai] [float] NULL,
[Plant_AreaShape] [float] NULL,
[Plant_CreateDate] [date] NULL,
[Plant_CreateBy] [nvarchar](150) NULL,
[Plant_CreateSeasonID] [int] NULL,
[Plant_Active] [bit] NOT NULL CONSTRAINT [DF_Table_1_PlantType_Status] DEFAULT ((1)),
[Plant_Created] [datetime] NOT NULL CONSTRAINT [DF_Table_1_PlantType_Created] DEFAULT (getdate()),
[Plant_Creator] [nvarchar](50) NOT NULL CONSTRAINT [DF_Table_1_PlantType_Creator] DEFAULT (N'system'),
[Plant_Changed] [datetime] NULL,
[Plant_Changer] [nvarchar](50) NULL,
CONSTRAINT [PK_tb_opr_Plant] PRIMARY KEY CLUSTERED
(
[Plant_ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
@MaxInnoTech
Copy link

ใส่ Trigger ด้วยครับ

/****** Object: Trigger [dbo].[TRG_opr_Plant_Update] ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TRIGGER [dbo].[TRG_opr_Plant_Update] ON [dbo].[tb_opr_Plant]
FOR UPDATE
AS

BEGIN

SET NOCOUNT ON

UPDATE  tb_opr_Plant 

SET Plant_Changed = GETDATE()
FROM tb_opr_Plant A
INNER JOIN Inserted INS ON (A.Plant_ID = INS.Plant_ID)

 SET NOCOUNT OFF

END

GO

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment