Files
DP44/DataPRO/Modules/Database/DatabaseMigrationScripts/MigrationScripts/Version63/SensorsDigitalIn_AddMeasurementUnitField.sql
2026-04-17 14:55:32 -04:00

82 lines
4.8 KiB
SQL
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
Monday, June 11, 20189:15:27 AM
User:
Server: FAJITA\DEV_SQL
Database: DataPRO
Application:
*/
/* To prevent any potential data loss issues, you should review this script in detail before running it outside the context of the database designer.*/
BEGIN TRANSACTION
SET QUOTED_IDENTIFIER ON
SET ARITHABORT ON
SET NUMERIC_ROUNDABORT OFF
SET CONCAT_NULL_YIELDS_NULL ON
SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON
COMMIT
BEGIN TRANSACTION
--GO
CREATE TABLE dbo.Tmp_SensorsDigitalIn
(
Id int NOT NULL IDENTITY (1, 1),
SerialNumber nvarchar(50) NOT NULL,
SettingMode int NOT NULL,
ScaleMultiplier nvarchar(50) NOT NULL,
LastModified datetime NOT NULL,
LastModifiedBy nvarchar(50) NOT NULL,
eId nvarchar(50) NOT NULL,
UserValue1 nvarchar(255) NULL,
UserValue2 nvarchar(255) NULL,
UserValue3 nvarchar(255) NULL,
UserTags varbinary(MAX) NULL,
MeasurementUnit nvarchar(50) NOT NULL DEFAULT 'V'
) ON [PRIMARY]
TEXTIMAGE_ON [PRIMARY]
--GO
ALTER TABLE dbo.Tmp_SensorsDigitalIn SET (LOCK_ESCALATION = TABLE)
--GO
SET IDENTITY_INSERT dbo.Tmp_SensorsDigitalIn ON
--GO
IF EXISTS(SELECT * FROM dbo.SensorsDigitalIn)
EXEC('INSERT INTO dbo.Tmp_SensorsDigitalIn (Id, SerialNumber, SettingMode, ScaleMultiplier, LastModified, LastModifiedBy, eId, UserValue1, UserValue2, UserValue3, UserTags)
SELECT Id, SerialNumber, SettingMode, ScaleMultiplier, LastModified, LastModifiedBy, eId, UserValue1, UserValue2, UserValue3, UserTags FROM dbo.SensorsDigitalIn WITH (HOLDLOCK TABLOCKX)')
--GO
SET IDENTITY_INSERT dbo.Tmp_SensorsDigitalIn OFF
--GO
ALTER TABLE dbo.Sensors
DROP CONSTRAINT FK_Sensors_SensorsDigitalIn
--GO
DROP TABLE dbo.SensorsDigitalIn
--GO
EXECUTE sp_rename N'dbo.Tmp_SensorsDigitalIn', N'SensorsDigitalIn', 'OBJECT'
--GO
ALTER TABLE dbo.SensorsDigitalIn ADD CONSTRAINT
PK__SensorsDigitalIn PRIMARY KEY CLUSTERED
(
Id
) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
--GO
COMMIT
BEGIN TRANSACTION
--GO
ALTER TABLE dbo.Sensors WITH NOCHECK ADD CONSTRAINT
FK_Sensors_SensorsDigitalIn FOREIGN KEY
(
SensorId
) REFERENCES dbo.SensorsDigitalIn
(
Id
) ON UPDATE NO ACTION
ON DELETE NO ACTION
--GO
ALTER TABLE dbo.Sensors
NOCHECK CONSTRAINT FK_Sensors_SensorsDigitalIn
--GO
ALTER TABLE dbo.Sensors SET (LOCK_ESCALATION = TABLE)
--GO
COMMIT