using column name as foreign key in sqlite
Is there a way to reference "column-names of given table" as foreign key in sqlite?
I've tested:
create table "test"(
t开发者_StackOverflowest TEXT
);
create table "othertest"(
othertest TEXT references PRAGMA table_info("test")[1]
);
But as expected, it does not work... (the error is Error: near "table_info": syntax error
, but even if table_info was accepted, I doubt that the [1]
part would be valid)
In general, SQL database management systems don't allow expressions in DDL. Systems that support information_schema views won't let you use a scalar subquery to return the target for a foreign key reference. This is a syntax error in all the SQL dbms I use day to day.
create table test (
article_id integer primary key
references articles (select column_name
from information_schema.columns
where table_name = 'articles'
and is_nullable = 'NO')
);
What is the real problem you need to solve by trying to do this?
精彩评论