[英]How to insert data into a vertically partitioned table in sql server
I have a problem with the partitioning of a table in the SQL Server
. 我在
SQL Server
中对表进行分区时遇到问题。 I have a table with over 103 columns out of which only 20 are used very frequently and are referenced by a number of tables. 我有一个超过103列的表,其中只有20列经常使用,并且被许多表引用。
As the table contains thousands of rows I have created a vertical partition and divided the table into multiple tables so as to save the table data in different file groups. 由于该表包含数千行,因此我创建了一个垂直分区,并将该表分为多个表,以便将表数据保存在不同的文件组中。
I have also created a view by joining those tables. 我还通过加入这些表创建了一个视图。 And now, how do i insert data into different tables without using
INSTEAD OF
triggers? 现在,如何在不使用
INSTEAD OF
触发器的情况下将数据插入不同的表?
You can use stored procedure to encapsulate all your insert logic. 您可以使用存储过程来封装所有插入逻辑。
If you have, let's say, 3 tables that share same ID column and each have it additional columns, your stored procedure might look something like this: 假设您有3个表共享相同的ID列,并且每个表都有其他列,那么您的存储过程可能如下所示:
CREATE PROCEDURE usp_Insert
(
@Val1 VARCHAR(5)
, @Val2 VARCHAR(5)
, @Val3 VARCHAR(5)
)
AS
BEGIN
DECLARE @id INT;
INSERT INTO Table1 (Col1) VALUES (@Val1);
SELECT @id = SCOPE_IDENTITY();
INSERT INTO Table2 (ID, Col2) VALUES (@id, @Val2);
INSERT INTO Table3 (ID, Col3) VALUES (@id, @Val3);
END
GO
SQLFiddle Working demo and sample tables SQLFiddle Working演示和示例表
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.