When creating a table in SQLite, I want to define the default value of a column using value from another table (as this column is a foreign key). Something like this:
CREATE TABLE Test_1(A1 INTEGER PRIMARY KEY, B1 TEXT NOT NULL);
CREATE TABLE Test_2(A2 INTEGER PRIMARY KEY, B2 INTEGER NOT NULL DEFAULT [a value in column A1 of Test_1]);
I assume that Test_1 is already populated with the records that provides possible values for B2 in Test_2 table. For example, these may be some constants like 'Created', 'In Progress', 'Paused', 'Finished' for a 'Status' column (i.e. B2).
I can of course pick the primary key of a value from Test_1 and hard code it as the default value for B2, but that is error prone if I change the data of Test_1 later. At the same time, we cannot use SELECT statement inside a CREATE.
If this is not feasible in SQLite, is it possible for other SQL engines? Or more generally, is this something that should be enforced by application logic rather than by database design?
Test_1are already there, e.g. they may be some constants for a certain column/field inTest_2. I merely want to use one of the constants defined inTest_1as the default value for the corresponding column inTest_2table.