Topic
[KB732]How to copy the contents of an HDS table to another SQL table or other relational database
Applies to:
All PcVue versions including the HDS |
||
|
||
Summary:
The SQL Server tools allow you to copy the contents of a table using two methods.
|
||
|
||
Details:
Copying on the fly (SQL trigger) A trigger is a database object that is attached to a table. It is similar to a stored procedure. A trigger is only fired when an INSERT, UPDATE or DELETE occurs. SQL Server uses a lot of processing time when calling a trigger and you must try to keep this to the minimum. The SQL script that inserts a trigger should be as short as possible and must never lock the write process.
Copying on demand (SQL script) If your application does not need to create a table copy on the fly it is preferable to request a snapshot of the table instead. Snapshot FAQ What is a snapshot – A database snapshot is a read-only, static view of a SQL Server database. The snapshot content is a copy of your database at a given time. To reiterate, if the source database content changes after the snapshot , the snapshot contents doesn’t change. Why use a snapshot – The main interest for PcVue is that the snapshot isolation does not cause lock escalation. A snapshot does not request a lock when reading data. You can select a large quantity of data or lock snapshot without disturbing the HDS table. Things to be aware of –
Example of a T-SQL script to create a snapshot /* CREATE AND UPDATE A SNAPSHOT */ declare @DBName sysname set @DBName = N’PRJ_DATABASE1′ SELECT @DBDataLogicalName=name FROM sys.master_files WHERE database_id = DB_ID(@DBName) AND type_desc = ‘ROWS’ IF (EXISTS(SELECT name FROM master.dbo.sysdatabases WHERE (‘[‘ + name + ‘]’ = @SSName OR name = @SSName))) BEGIN SELECT @REQ_CreateSnap = ‘CREATE DATABASE ‘ + @SSName + EXEC(@REQ_CreateSnap) Other useful scripts /* USE YOUR SNAPSHOT INSTEAD YOUR DATABASE */ SELECT * FROM [PRJ_DATABASE1_ss].[dbo].TRENDTABLE1 /* LOCK YOUR TABLE */ BEGIN TRANSACTION /* SHOW LOCKS */ SELECT FROM sys.dm_tran_locks; Further reading Lock escalation: http://technet.microsoft.com/en-US/en-en/library/ms184286(v=sql.105).aspx |
||
|
||
|
Created on: 12 Feb 2015 Last update: 04 Sep 2024