Note that there are some explanatory texts on larger screens.

plurals
  1. PODetermining Oracle Column gets filled by sequence and trigger (Identity Column like SQLServer)
    primarykey
    data
    text
    <p>I have to determine, if a column gets filled up automatically.</p> <p>Mostly this is done at PrimaryKey Columns. This has to be done with Oracle database as well as with SQLServer.</p> <p>The background of my question is (only for your better understanding), i'm reading a XML File where the specification says, the element tags match column names of a table. The table will be given by the user and he chooses the xml File i have to parse. After that i am looking for all the elements inside the xml file, if they are matching a column's name in the table.</p> <p>It is not clear if the xml file will give me Primary Key information. It could be, but could also not be. If the column's name will be inside the xml all would be fine. But if not, i have to look up if</p> <ul> <li>i have a PK Column given in the xml File and also</li> <li>if that PK column is automatically filled up with values</li> </ul> <p>if this is not given, i have to raise an exception. Therefor i have to determine that Schema Information.</p> <p>With SQLServer, it is no problem. IsAutoIncrement will be true, if it is an Identity Column.</p> <p>I read the table schema data like this (only short example)</p> <pre><code>System.Data.Common.DbDataReader reader = command.ExecuteReader(CommandBehavior.KeyInfo); dtTable = reader.GetSchemaTable(); </code></pre> <p>Now i'm getting all the information i want. Unfortunatelly with Oracle, the IsAutoIncrement property is set to false.</p> <p>I know, how should GetSchemaTable() determine if the column is set by an sequence if it is not stated at the Column by the DBMS, as SQLServer does. That is clear to me.</p> <p>Does anyone have a idea, how to solve this? Determining if a column in a table gets filled by a sequence inside a trigger? Maybe parsing the triggers body?</p> <p>Thanks in advance for any help</p> <p><strong>My solution looks like this now:</strong></p> <pre><code> if (IsOracleClient) { // reading Trigger Information string sql = "select\n" + " a.trigger_body\n" + " from\n" + " all_triggers a,\n" + " all_trigger_cols b\n" + " where\n" + " a.table_name = '{0}'\n" + " and b.table_name = a.table_name\n" + " and b.column_name = '{1}'\n" + " and a.trigger_name = b.trigger_name"; command.CommandText = String.Format(sql, this.Tabelle.ToUpper(), this.PrimaryKeyColumn.ColumnName.ToUpper()); using (System.Data.Common.DbDataReader reader = command.ExecuteReader()) { if (reader.HasRows) { reader.Read(); string body = reader.GetString(0); if (body.Contains("NEXTVAL")) this.PrimaryKeyColumn.IsAutoIncrement = true; } reader.Close(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload