How to get last accessed date of a table and the user who accessed the table in db2 LUW - db2

I have a db2 LUW database, i'm able to get last accessed date using last_used column from syscat.tables, i also need the user name or id who is trying to access thsi table. Is there any system table or view that stores this info. If this is not possible, is there any system table or view that stores history of queries executed along with username and time of execution in db2.

Related

Cloudant/Db2 - How to determine if a database table row was read from?

I have two databases - Cloudant and IBM Db2. I have a table in each of these databases that hold static data that is only read from and never updated. These were created a long time ago and I'm not sure if they are used today so I wish to do a clean-up.
I want to determine if these tables or rows from these tables, are still being read from.
Is there a way to record the read timestamp (or at least know if it is simply accessed like a dirty bit) on a row of the table when it is read from?
OR
Record the read timestamp of the entire table (if any record from it is accessed)?
There is SYSCAT.TABLES.LASTUSED system catalog column in Db2 for DML statements on whole table.
There is no way to track each table row read access.

MS Access - PostgreSQL auto number

I have a frontend in ms access and a backend in Postgresql. The database used to be on SQL Server before moving onto Postgresql. Most tables have a column called ID that is an AutoNumber in Access, so it gets the next ID automatically. It used to work fine on simple Access (database started on accdb file) and then when it was moved to SQL server.
After moving to PostgreSQL though the column is now labeled as "Number" in Access and it doesn't give new IDs when a new record is added, this causes a "Primary Key cannot be null" error. The Column ID is set to INTEGER with IDENTITY: Always and an increment of 1. Obviously I cannot alter the table in Access and change number into autonumber because it's read-only as a linked table.
How can I make Ms Access recognize the IDENTIFY column of PostgreSQL as an AutoNumber?
Edit with some more information:
I have a table called Orders and a table called Jobs. Each Order has multiple Jobs and they are connected with an OrderID column. Adding an Order without any Jobs works fine (even though the column is "Number" instead of "AutoNumber" Postgres creates new unique values correctly) The problem comes when I add a Job to that Order, I get "Primary Key cannot be null" error.
I added the Job ID field to be visible on the form and it doesn't have any value while I edit the other columns of the Job form. I used to create a new ID using Me.Dirty = False on the Job adding form, and that's the exact point where the error is reported. So Me.Dirty = False doesn't create a new ID on Postgres, but it creates one just fine on Access or SQL Server.

Dynamic table selection

Is it possible to dynamically select a table by name?
For example I have a table, and every time records are uploaded to it a backup is created first with the date appended to the table name.
table_20191108
table_20191109
table_20191110
table_20191111
What I would like to do is basically write some type of dynamic sql that always
select * from table_MAXDATE
I would like to do this so I can compare table to the most recent backup (e.g. table_20191111) in order to see what changed between the two tables.
haven't tried anything specific yet.

Sharing list of database tables that can be manipulated in IBM DB2

I recently learnt about SELECT * FROM FINAL TABLE. FINAL TABLE is one of a unique table or view provided by IBM DB2 for us to get the records of last inserted row.
However, I would like to know other than FINAL TABLE. What are other type of tables are available for us to manipulate in my program.

Advantage database how to retieve connection name

I am using Sybase Advantage, I have 2 tables:
The first table has the data records
The second table stores a history of the first
The first table has triggers to populate records in the second table depending on which fields get changed.
I would like to store the connection name (PC which made the request), the name that is displayed in the active queries page (Server Info dialog) and not the username. Does anyone know if this is possible?
Thanks
The following SQL statement can be used to retrieve the computer name instead of the user name.
SELECT *
FROM
( EXECUTE PROCEDURE sp_mgGetConnectedUsers() ) ConnUsers
WHERE
ConnUsers.DictionaryUser = USER();
The stored procedure sp_mgGetConnectedUsers is documented here.