I have such database on SQLite:
CREATE TABLE [ArtTag] (
[article_id] integer NOT NULL,
[tag_id] integer NOT NULL,
CONSTRAINT [FK_ArtTag_article_id_Articles_id] FOREIGN KEY ([article_id]) REFERENCES [Articles] ([id]),
CONSTRAINT [FK_ArtTag_tag_id_Tags_id] FOREIGN KEY ([tag_id]) REFERENCES [Tags] ([id])
);
CREATE TABLE [Articles] (
[id] integer PRIMARY KEY AUTOINCREMENT NOT NULL,
[title] nvarchar(200) NOT NULL,
[author] nvarchar(50) NOT NULL,
[blog] nvarchar(50) NOT NULL,
[burl] nvarchar(255) NOT NULL,
[content] ntext NOT NULL,
[date] datetime NOT NULL
);
CREATE TABLE [Tags] (
[id] integer PRIMARY KEY AUTOINCREMENT NOT NULL,
[name] nvarchar(50) NOT NULL UNIQUE ON CONFLICT IGNORE
);
CREATE UNIQUE INDEX [IX_article_id_tag_id] ON [ArtTag] ([article_id], [tag_id]);
tag_id can be taken from the expression last_insert_rowid ()
, if the record does not exist, or select name from Tags where ...
if a record exists in table Tags. How to insert a row into a table ArtTag, if I know the article_id?