Configuration
- Database Engine = mybusiness.database.windows.net
- Records Database = Records --> dbo.accesslogs
- Legal Database = Legal --> dbo.personalinfo
- Access Database = Access --> dbo.accessinfo
Problem Description
- When people join the company their personal data such as employeeID (PK), name, gender, taxCode, address etc is entered into the dbo.personalinfo table of the Legal database. This is a very controlled database.
- People given access to our offices by key-swipe-tokens which are enrolled into the system and their employeeID (FK), tokenID (PK) and other details such where there token works and doesn't work are stored in the dbo.accessinfo table of the Access database.
- When anyone swipes their building access token the tokenID (FK), accessPoint, dateAndTime, accessID (PK) is recorded in the dbo.accesslogs table of the Records database. The accessID is unique for every scan (whether successful or not) of a RFID token.
- After people leave we need to purge their data from the dbo.accesslogs table. We aim to do this by creating an elastic query from the Legal database, as follows.
- T-Sql query in the Legal database creates External table of the dbo.accessinfo table from the Access database.
- T-Sql query in the Legal database creates External table of the dbo.accesslogs table from the Records database.
- T-Sql query in the Legal database creates Temporary table called #userrecords which contains every accessID for every tokenID corresponding to that user's specific employeeID.
Question
How do I construct a T-Sql query from the Legal database that uses the accessID from the temporary table to delete the rows of the dbo.accesslogs table in the Records database?