SSIS 2005 Transformations Used for Auditing? - sql-server

I have two tables in our data warehouse which need to be audited on several levels. The structure of the first table is as follows:
CREATE TABLE [dbo].[EnctrAPR](
[EncounterNumber] [varchar](50) NOT NULL,
[MedRec] [varchar](50) NULL,
[AdmitDate ] [datetime] NULL,
[DischargeDate ] [datetime] NULL,
[Age ] [varchar](50) NULL,
[Disposition ] [varchar](50) NULL,
[DRG ] [varchar](50) NULL,
[APRDRG ] [varchar](50) NULL,
[APRDRGWeight] [varchar](50) NULL,
[SOI] [varchar](50) NULL,
[ROM] [varchar](50) NULL,
[Age18] [bit] NULL,
[Age18To64] [bit] NULL,
[Age65] [bit] NULL,
[BowelObstruction] [bit] NULL,
[AMI] [bit] NULL,
[CABG] [bit] NULL,
[Valve] [bit] NULL,
[PCI] [bit] NULL,
[Sepsis] [bit] NULL,
[GSP] [bit] NULL,
[HF] [bit] NULL,
[Stroke] [bit] NULL,
[Pneumonia] [bit] NULL,
[DKA] [bit] NULL,
[GIBleed] [bit] NULL,
[Pancreatitis] [bit] NULL,
[RF] [bit] NULL,
[PE] [bit] NULL,
[COPD] [bit] NULL,
CONSTRAINT [PK_EnctrAPR] PRIMARY KEY CLUSTERED
(
[EncounterNumber] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON,
ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
I need to do several audits against another table in the data warehouse. They are:
Identify records in above table that aren't in the DWH table.
Identify records in the DWH table that aren't in the above table.
Document records where each of the bit fields above is TRUE but are FALSE in the DWH.
Confirm overall record count for a given date range.
Can I use SSIS to accomplish these audits? Or, would a combinaion of stored procedures and SSIS be the best bet? Please provide me with some suggestions on ow to best automate such auditing.

You could use the Lookup Transformation in SSIS to accomplish this, but this component is a little slow. If the databases are on different servers I would be inclined to use SSIS. If they are in the same instance, I would probably use a Stored Procedure without SSIS.
If you do use the SSIS approach, you would have a OLEDB source to read the rows from ODH, a lookup transformation against the table above and then write the results out to a destination.
I see no benefit on combining SSIS and an SP for this specific task.

Related

The table does not support the 'updatedAt' system property

I recently lost an Azure database (there's no recovering it...) and had to recreate from scratch. This database is supposed to sync to our iOS app, which allows us to keep the data between the DB and Device in sync. Unfortunately, after recreating the database and tables manually (because I'm not sure how else to do it?), my App Service is able to connect to the SQL database, and from the app side it looks like it's syncing, but when I look at the logs, I'm seeing the following error for each table, and I get no data:
The table 'tablename' does not support the 'updatedAt' system
property.
I've searched everywhere for this system property and cannot for the life of me find out where it's at or how to relate it to the database tables.
Here's an example of a schema for a table I'm having issues with:
CREATE TABLE [dbo].[CurrentItems](
[id] [nvarchar](128) NOT NULL,
[siteID] [nvarchar](max) NOT NULL,
[residentUnitNumber] [nvarchar](50) NULL,
[residentID] [nvarchar](max) NULL,
[pinUsedToCheckOut] [nvarchar](max) NULL,
[itemType] [nvarchar](max) NULL,
[itemTrackingNumber] [nvarchar](max) NULL,
[itemNotes] [nvarchar](max) NULL,
[itemID] [nvarchar](max) NULL,
[deviceSerialNumber] [nvarchar](max) NULL,
[dateRecordCreated] [datetime] NOT NULL,
[dateLastModified] [datetime] NULL,
[dateItemCheckedOut] [datetime] NULL,
[dateItemCheckedIn] [datetime] NULL,
[currentStatus] [nvarchar](max) NOT NULL,
[checkedOutEmpID] [nvarchar](max) NULL,
[checkedInEmpID] [nvarchar](max) NOT NULL,
[carrierName] [nvarchar](max) NULL,
[barcodeValue] [nvarchar](max) NULL,
[version] [timestamp] NOT NULL,
[deleted] [bit] NOT NULL,
[createdAt] [datetimeoffset](7) NOT NULL,
[updatedAt] [datetimeoffset](7) NOT NULL,
CONSTRAINT [PK_CurrentItems] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
I really need to get this app back to syncing, even if that means starting from scratch, but I can't seem to find the instructions for that on the Azure website anymore, so I don't know what else to do.
Any help or guidance anyone can provide would be greatly appreciated!

How to fix "There is already an object named ' ' in the database" error in sql server

I have created this table, I can't enter data manually because of this error.
USE [Butterfly]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[VM_Vehicles](
[VehicleID] [nvarchar](100) NOT NULL,
[VehicleType] [nvarchar](100) NULL,
[RegistrationNo] [nvarchar](100) NULL,
[PurchaseDate] [date] NULL,
[Make] [nvarchar](100) NULL,
[Model] [nvarchar](100) NULL,
[ChassisNo] [nvarchar](100) NULL,
[EngineNo] [nvarchar](100) NULL,
[EngineCapacity] [nvarchar](100) NULL,
[YearofManufacture] [nvarchar](100) NULL,
[SeatingCapacity] [nvarchar](100) NULL,
[ContactName] [nvarchar](100) NULL,
[Phone] [nvarchar](50) NULL,
[VendorID] [int] NOT NULL,
[Picture] [image] NULL,
[VoucherNo] [int] NOT NULL,
CONSTRAINT [PK_VM_Vehicles1] PRIMARY KEY CLUSTERED
(
[VehicleID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
I have tried using this code to find what's wrong with my database. so far no luck finding error.
IF object_id("tempdb..#VM_Vehicles") is not null
DROP TABLE #VM_Vehicles
CREATE TABLE #VM_Vehicles (vehicleID nvarchar(100), ...);
I already tried changing constraint name and table name. That didn't provide me a answer either.
You are creating a persistent table VM_Vehicles in database Butterfly. However, you are checking a temporary table #VM_Vehicles in database TempDB:
IF object_id("tempdb..#VM_Vehicles") is not null
So you are checking another table from another database and so you have a such error:
There is already an object named ' ' in the database
The correct check statement should look like this:
USE Butterfly
IF OBJECT_ID("VM_Vehicles") IS NOT NULL DROP TABLE VM_Vehicles
CREATE TABLE [dbo].[VM_Vehicles](VehicleID nvarchar(100), ...);

Increase Performance of SSIS DFT

Im loading 13 cr rows of data from DB2 to SQL server.
currently I have implemented fast load option and set up batch and commit size. thus improved some performance. Please suggest to improve further.
Current version : ssis 2012 and SQL server : 2014
CREATE TABLE tbl(
[ID] [bigint] NULL,
[CTYPE] [bigint] NULL,
[A_ID] [bigint] NULL,
[AC_TYPE] [bigint] NULL,
[ASS_TYPE] [nvarchar](400) NULL,
[t_ID] [bigint] NULL,
[A_T_ID] [bigint] NULL,
[FLAG] [int] NULL,
[REGION] [nvarchar](50) NULL,
[CHANGEDATE] [datetime] NULL,
[FLAG2] [nvarchar](50) NULL
) ON [PRIMARY]
GO

Can't create relationships in SQL Server diagram

I'm using SQL Server Management Studio 2008 R2 to create a database diagram. I've dropped in the tables that already have foreign key relationships; in addition, all the tables have primary keys. However, when I try to drag and drop from either table onto the other, I get the following error popup:
Primary key or UNIQUE constraint must be defined for table 'Results' before it can participate in a relationship.
Again, both tables have primary keys. The database was imported via Microsoft's SQL Server Migration Assistant for Access tool to preserve relationships and keys. What am I doing wrong?
Update: Here's the table:
CREATE TABLE [dbo].[Results](
[Result_AN] [int] IDENTITY(1,1) NOT NULL,
[Detail_AN] [int] NULL,
[Drug] [nvarchar](10) NULL,
[LDrug] [nvarchar](10) NULL,
[Lab_Result] [nvarchar](10) NULL,
[MRO_Result] [nvarchar](10) NULL,
[Confirm] [nvarchar](6) NULL,
[CutOff] [nvarchar](6) NULL,
[Quant] [nvarchar](10) NULL,
[Screen] [nvarchar](6) NULL,
[Unit] [nvarchar](6) NULL,
[Deleted] [bit] NULL,
[Scrn_Result] [nvarchar](10) NULL,
[SSMA_TimeStamp] [timestamp] NOT NULL,
CONSTRAINT [Results$PrimaryKey] PRIMARY KEY CLUSTERED
(
[Result_AN] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

Need advice on table relations

I have a table Users:
[UserId] [int] IDENTITY(1,1) NOT NULL,
[UserName] [nvarchar](20) NOT NULL,
[Email] [nvarchar](100) NOT NULL,
[Password] [nvarchar](128) NOT NULL,
[PasswordSalt] [nvarchar](128) NOT NULL,
[Comments] [nvarchar](256) NULL,
[CreatedDate] [datetime] NOT NULL,
[LastModifiedDate] [datetime] NULL,
[LastLoginDate] [datetime] NOT NULL,
[LastLoginIp] [nvarchar](40) NULL,
[IsActivated] [bit] NOT NULL,
[IsLockedOut] [bit] NOT NULL,
[LastLockedOutDate] [datetime] NOT NULL,
[LastLockedOutReason] [nvarchar](256) NULL,
[NewPasswordKey] [nvarchar](128) NULL,
[NewPasswordRequested] [datetime] NULL,
[NewEmail] [nvarchar](100) NULL,
[NewEmailKey] [nvarchar](128) NULL,
[NewEmailRequested] [datetime] NULL
This table has 1 to 1 relation to Profiles:
[UserId] [int] NOT NULL,
[FirstName] [nvarchar](25) NULL,
[LastName] [nvarchar](25) NULL,
[Sex] [bit] NULL,
[BirthDay] [smalldatetime] NULL,
[MartialStatus] [int] NULL
I need to connect user to the all other tables in database so is it better to:
1) Make relations from Users - to other tables?
2) Make relations from Profiles - to other tables?
Since the table [Users] contains the Identity value and is therefore where the [UserID] value originates, I would create all the foreign keys back to it. From a performance standpoint, assuming you have your clustered index on both tables set on the [UserID] column there should be very little performance impact.
Technically I suppose the [Users] table could contain more data per row and therefore the index could span more pages and you could have milliseconds difference in lookups, but I think it makes more sense to relate it back to the table that created the [UserID] and is similarly named. That said, you can really do either.
If the PK of Profiles is a FK to Users, I would maintain consistency and use Users as the parent table in other relationships across the database.
However, if it is a true one-to-one and not a one-to-zero or one relationship, it doesn't matter.
Another consideration is how the data in this database is accessed by any applications. Do the applications use an OR/M like Entity Framework which is aware of FK relationships? If so, consider using whichever table has columns which will most commonly be accessed by queries based on the child tables. For example, an application might display Profiles.LastName and Profiles.FirstName all over the place and very rarely read anything from the Users table. In this situation, you will save your database some I/O and save your developers some keystrokes by building relationships off the Profiles table.

Resources