我正在使用客户关系管理应用程序。我有两个表:tbl_Inquiry_master
用于存储最终用户提出的查询问题详细信息,以及tbl_Inquiry_History
用于存储查询答案详细信息。
然而,这显示了将一个问题存储到 table 的知识tbl_Inquiry_master
以及工作人员对存储在 table 中的查询给出的答案tbl_Inquiry_History
。
有关更多信息,我表示表tbl_Inquiry_master
模式:
Column Name Data Type
_________________________________________
Id varchar(50)
Inquiry_subject varchar(100)
Status_id numeric(18, 0)
Created_date datetime
Priority_id numeric(18, 0)
User_id varchar(50)
Email_Address varchar(50)
Service_id numeric(18, 0)
Inquiry_Content varchar(1024)
TimeStamp datetime
表tbl_Inquiry_History
架构:
Column Name Data Type
_________________________________________
Id numeric(18, 0)
Inquiry_id varchar(50)
Inquiry_subject varchar(50)
Service_id numeric(18, 0)
Priority_id numeric(18, 0)
User_id varchar(50)
Status_id numeric(18, 0)
Inquiry_desc varchar(1024)
IsDisplay bit
IsRead bit
IsReplied bit
TimeStamp datetime
Activity_start_time datetime
Activity_expire_time datetime
表tbl_User_master
架构:
Column Name Data Type PK/FK Reg Table Ref Key
____________________________________________________________________________________
Id varchar(50) PK - -
User_id varchar(50) FK tbl_Login_master Id
Full_Name varchar(50)
.
.
Email_Address varchar(50)
表tbl_Question
架构:
Column Name DatType PK/FK Ref Table Ref Key
____________________________________________________________________
Id int PK - -
UserId varchar(50) FK tbl_User_master Id
Body varchar(1024)
Inquiry_Id varchar(50) FK tbl_Inquiry_master Id
表tbl_Answer
架构:
Column Name DatType PK/FK Ref Table Ref Key
____________________________________________________________________
Id int PK - -
QuestionId int FK tbl_Question Id
Body varchar(1024)
Inquiry_Id varchar(50) FK tbl_Inquiry_master Id
但是我不知道如何存储多个 Inquiry 的问题(由最终用户提出)和多个 Inquiry 的答案(由员工用户给出)。
我将这个存储过程包括在我如何插入从最终用户生成的新查询以及如何将信息存储到表层次结构中。
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[InsertInquiry]
(
@Inquiry_subject VARCHAR(50),
@Service_name VARCHAR(50),
@Priority_type VARCHAR(25),
@User_id VARCHAR(50),
@Inquiry_desc VARCHAR(1024),
@email VARCHAR(50),
@NewId VARCHAR(50) OUT
)
AS
SET NOCOUNT ON;
declare @var1 int
declare @var2 int
declare @var3 int
declare @uniqueRef char(14)
set @uniqueRef = dbo.UniqueRefNum(rand(), rand(), rand(), rand())
BEGIN TRAN;
BEGIN TRY
SET @var1= (SELECT [Id] FROM [OmStocks].[dbo].[tbl_Status_master] WHERE (Status_name='Open'))
SET @var2= (SELECT [Id] FROM [OmStocks].[dbo].[tbl_Service_master] WHERE (Service_name=@Service_name))
SET @var3= (SELECT [Id] FROM [OmStocks].[dbo].[tbl_Priority_master] WHERE (Priority_name=@Priority_type))
INSERT INTO [OmStocks].[dbo].[tbl_Inquiry_master]
([Id]
,[Inquiry_subject]
,[Status_id]
,[Created_date]
,[Priority_id]
,[User_id]
,[Email_Address]
,[Service_id]
,[Inquiry_desc])
VALUES
(@uniqueRef,@Inquiry_subject,@var1,CONVERT(DATETIME,GETDATE(), 101),@var3,@User_id,@email,@var2,@Inquiry_desc)
INSERT INTO [OmStocks].[dbo].[tbl_Question]
([UserId],[Body],[Inquiry_Id])
VALUES
(@User_id,@Inquiry_desc,@uniqueRef)
INSERT INTO [OmStocks].[dbo].[tbl_Inquiry_History]
([Inquiry_id]
,[Inquiry_subject]
,[Service_id]
,[Priority_id]
,[User_id]
,[Status_id]
,[Inquiry_desc]
,[IsDisplay]
,[IsRead]
,[IsReplied]
,[Activity_start_time])
VALUES
(@uniqueRef,@Inquiry_subject,@var2,@var3,@User_id,@var1,@Inquiry_desc,0,0,0,CONVERT(DATETIME,GETDATE(), 101))
SET @NewId= @uniqueRef
COMMIT TRAN;
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION;
-- Raise the error with the appropriate message and error severity
DECLARE @ErrMsg nvarchar(4000), @ErrSeverity int;
SELECT @ErrMsg = ERROR_MESSAGE(), @ErrSeverity = ERROR_SEVERITY();
RAISERROR(@ErrMsg, @ErrSeverity, 1);
END CATCH;
有人可以建议我对架构进行更改以存储此场景的数据吗?