Last modification time for table DDL metadata - database

Is there a system view in SAP HANA that contains last modification time for a table?
The time should contain timestamp when table DDL was changed, so I am interested particularly in table metadata last modification time.
For example I'd like to know when a column was added to the table or when a column was removed from the table.
The question isn't about SYS.M_TABLE_STATISTICS that contains information about last DML statement for the table.

You can use new system view M_EXECUTED_STATEMENTS. It monitors all DDL changes to the tables including:
All SQL statements starting with CREATE, DROP, ALTER, and RENAME. For example, CREATE TABLE, CREATE USER and ALTER TABLE.
All SQL statements starting with TRUNCATE, GRANT, REVOKE, LOAD, EXPORT, IMPORT, and COMMENT.
The SET SYSTEM LICENSE and UNSET SYSTEM LICENSE ALL statements.
It is enabled by default globally and was added in HANA SPS 11 exactly for that aim, i.e. for tracking invalid metadata issues.

Related

How to update the origin table in the CDC workflow (via SSIS)?

I have a CDC process setup, whereby TableA's additional rows (or updates) are automatically picked up by an ETL and put into a TableB
TableA >>CDC>> TableB
The CDC works fine, except I want to update the first table once the CDC process is finished. I want to update the table by populating it with the
"extraction date". So my tableA has, lets say: Name, Age, OtherInfo, ExtractionDate. CDC is setup on Name,Age and OtherInfo columns (extractionDate column is excluded for obvious reasons).
Then, once CDC is performed on TableA and it's taken to TableB, I'd like to populate TableA's "extractionDate" with the current date. However, given I do not know which rows are being moved, I am having difficulty populating the column. Specifically, how can I make a "selective" where clause to select the "changed" rows, when that's only known to SSIS.
In the Table A database there are system tables that were created as part enabling CDC. You should be able to easily find the table associated with Table A. This is where MSSQL keeps track of all the changes.
The __$start_lsn is a timestamp of when the change was made and your SSIS imports use this value to bring across a range of changes. The lsn_time_mapping lets you look up the timestamp so it easier to understand.
In my processing I store the start and end lsn values so I know what was brought across with each SSIS run. I could then use these lsn values to go back to this CDC source table and see all the changes that MSSQL has tracked during that time-span.
Keep in mind that the CDC system tables are automatically cleaned out every few days - so you wouldn't be able to applyt this logic historically - only for recent imports.

Changing columns to identity (SQL Server)

My company has an application with a bunch of database tables that used to use a sequence table to determine the next value to use. Recently, we switched this to using an identity property. The problem is that in order to upgrade a client to the latest version of the software, we have to change about 150 tables to identity. To do this manually, you can right click on a table, choose design, change (Is Identity) to "Yes" and then save the table. From what I understand, in the background, SQL Server exports this to a temporary table, drops the table and then copies everything back into the new table. Clients may have their own unique indexes and possibly other things specific to the client, so making a generic script isn't really an option.
It would be really awesome if there was a stored procedure for scripting this task rather than doing it in the GUI (which takes FOREVER). We made a macro that can go through and do this, but even then, it takes a long time to run and is error prone. Something like: exec sp_change_to_identity 'table_name', 'column name'
Does something like this exist? If not, how would you handle this situation?
Update: This is SQL Server 2008 R2.
This is what SSMS seems to do:
Obtain and Drop all the foreign keys pointing to the original table.
Obtain the Indexes, Triggers, Foreign Keys and Statistics of the original table.
Create a temp_table with the same schema as the original table, with the Identity field.
Insert into temp_table all the rows from the original table (Identity_Insert On).
Drop the original table (this will drop its indexes, triggers, foreign keys and statistics)
Rename temp_table to the original table name
Recreate the foreign keys obtained in (1)
Recreate the objects obtained in (2)

CDC table not working after adding new columns to the source table

Two new columns were added to our source table while CDC was still enabled on the table. I need the new columns to appear in the CDC table but do not know what procedure should be followed to do this? I have already disabled CDC on the table, disabled CDC on the DB, added the new columns to the cdc.captured_columns table, and enabled CDC. But now I am getting no data in the CDC table!
Is there some other CDC table that must be updated after columns are added to the source table? These are all the CDC tables under the System Tables folder:
cdc.captured_columns <----- where I added the new columns
cdc.change_tables
cdc.dbo_myTable_CT <------ table where change data was being captured
cdc.ddl_history
cdc.index_columns
cdc.lsn_time_mapping
dbo.systranschemas
I recommend reading Tracking Changes in Your Enterprise Database. Is very detailed and deep. Among other extremly useful bits of info, there is such as:
DDL changes are unrestricted while change data capture is enabled.
However, they may have some effect on the change data collected if
columns are added or dropped. If a tracked column is dropped, all
further entries in the capture instance will have NULL for that
column. If a column is added, it will be ignored by the capture
instance. In other words, the shape of the capture instance is set
when it is created.
If column changes are required, it is possible to create another capture instance for a table (to a maximum of two capture instances per table) and allow consumers of the change data to migrate to the new table schema.
This is a very sensible and well thought design that considers schema drift (not all participants can have the schema updated simultaneously in a real online deployment). Having a multi-staged approach (deploy DDL, capture new CDC, upgrade subscribers, drop old CDC capture) is the only feasible approach and you should follow suit.

Is it possible to make postgres automatically update the column definition of an auditory table?

I have the following question, I am using audit tables for some entities in my project so for instance if there is a "people" table there will be a "public_people_audit" table (where "public" is the schema where the table is and "audit" is just a suffix that was chosen).
Now the thing is that when someone from the team modifies the "people" table and adds a column to it they may forget to do it on the auditory table and the system will fail because it will try to insert the new column value in the audit table and it won't find it.
I know that the team should be careful and put the modification in both tables, but if there could be a way of automating this so if someone makes an "ALTER TABLE people ADD COLUMN foo VARCHAR(10)" the same command will be executed on the public_people_audit table it would be very helpful.
The short answer: no.
The longer answer is you can automate this by create a quick script. Make a simple text file listing a few tables that need auditing. The script reads the text file, looks at the columns in the base tables, and makes sure any missing columns are added to the audit table.

SQL Server replication drop vs truncate of target tables

The sp_addarticle stored procedure, used to create publication articles in SQL Server speak, has a parameter #pre_creation_cmd through which dropping the table or truncating data at the target server can be specified for a snapshot. What circumstances are appropriate for each?
#pre_creation_cmd accepts one of four values:
NONE
DELETE
DROP
TRUNCATE
DELETE TABLE
Assume that your Published article
data is filtered and that the
corresponding table in the
Subscription receives data from other
sources, perhaps another Publication
for example. Using the DELETE
operation for this parameter would
delete "only" the data the meets the
criteria of the filter definition,
leaving the remaining data at the
Subscriber intact.
TRUNCATE TABLE
Removes all rows from a table without
logging the individual row deletions.
TRUNCATE TABLE is similar to the
DELETE statement with no WHERE clause;
however, TRUNCATE TABLE is faster and
uses fewer system and transaction log
resources.
DROP TABLE
Removes one or more table definitions
and all data, indexes, triggers,
constraints, and permission
specifications for those tables.

Resources