SQL Server 內相關設定
在 TempDB 內建立 Employee Table
USE [tempdb]
GO
CREATE TABLE [dbo].[Employee](
[UserID] [int] IDENTITY(1,1) NOT NULL Primary Key,
[UserName] [char](20) NULL,
[HireDate] [datetime] NULL,
[Age] [tinyint] NULL)
GO
INSERT INTO Employee (UserName , HireDate , Age)
VALUES('張三' , '2019-06-01' , 30)
INSERT INTO Employee (UserName , HireDate , Age)
VALUES('李四' , '2018-12-11' , 25)
建立 Insert、Update 和 Delete Store Procedure
-- Insert
CREATE PROCEDURE [dbo].[dmlEmployee_Insert]
(
@UserName char(10) ,
@HireDate datetime ,
@Age int ,
@UserID int output
)
AS
BEGIN
SET NOCOUNT ON;
INSERT INTO Employee (UserName , HireDate , Age)
VALUES(@UserName , @HireDate , @Age)
SET @UserID = SCOPE_IDENTITY()
END
GO
-- Update
CREATE PROCEDURE [dbo].[dmlEmployee_Update]
(
@UserID int ,
@UserName char(10) ,
@HireDate datetime ,
@Age int
)
AS
BEGIN
SET NOCOUNT ON;
UPDATE Employee
SET UserName = @UserName ,
HireDate = @HireDate ,
Age = @Age
WHERE UserID = @UserID
END
GO
-- Delete
CREATE PROCEDURE [dbo].[dmlEmployee_Delete]
(
@UserID int
)
AS
BEGIN
SET NOCOUNT ON;
DELETE FROM Employee WHERE UserID = @UserID
END
GO
CursorAdapter 設定AutoUpdate Tag => Advanced Button
覆蓋自動產生的 insert、update 和 delete 語法
利用 SQL Profile 來側錄 insert、update 和 delete 語法,確定有使用 SP
沒有留言:
張貼留言