I am very much new to the DB world, so wanted to review whether I am following right approach or not. I have two tables, table A --> is a table with 40 columns table B --> is a table with the 2 columns (each column of table A is represented as row in this table.)
Example:
A:
column_1 | column_2 | column_3 ......... | column_40
-----------------------------------------------------------
value1_1 | value1_2 | value1_3...... | value1_40
B:
column_name |column_value | column_errorKey
----------------------------------------------------
column_1 | value1_1 | value1_1_errorKey
column_2 | value1_2 | value1_2_errorKey
What am I doing?
Validate each value of a row from table A and insert into the table B with its value, error key and corresponding column name.
My PL SQL code is as below for, (Note: SQL code has considered only two columns to minimize the code here)
INSERT WHEN (LENGTH(column_1) <=7) THEN
into table_B values(
'column_1',column_1,'NoError')
WHEN (LENGTH(column_1) >7) THEN
into table_B values(
'column_1',column_1,'invalidLength')
WHEN (LENGTH(column_2) <= 75) THEN
into table_B values(
'column_2',column_2,'NoError')
WHEN (LENGTH(column_2) > 75) THEN
into table_B values(
'column_2',column_2,'invalidLength')
( select column_1,column_2,...,column_40
from table_A );
The validation that is happening within When the condition has only one validation but we have more validation like this for the value of each cell. I wanted to know is I am in the right approach or is another better way we have.
column 1 varchar2(7) not null, and enforcing more complicated rules with primary and unique keys, check constraints and foreign keys on valid values in other tables. We get all this stuff virtually for free. You should consider whether you have fully used your database's built-in capabilities before your start coding some horrible unmaintainable monstrosity.