English 中文(简体)
在满足条件时,插入表格3
原标题:Insert into a table if a condition is met with sqlite3

如果我有两个表格:files(id, Owner) Common(file_id,user),其中所有人和用户将成为理论用户表中的主要识别码,那么我如何插入>>。 只有当进行共享的用户拥有这一档案时才能这样做?

这是一个 stripped淡的例子,因此,我只用字面来进行股份操作——通常这种价值来自一届会议。 因此,如果我有:

files:
id: 1, owner: 1

用户2希望查阅档案1,我将利用这一询问:

insert into share values (1, 2)

但这只允许——用户2只手提1,用户1。 我正试图在一个方面这样做,但我可以说出。 我已尝试:

case when (select owner from files where id=1) is 2
    then (insert into share values (1, 2));

case (select owner from files where id=1) is 2
    then (insert into share values (1, 2));

insert into share values (1, 2)
    where 2 not in (select owner from files where id=1)

并且都是同学错误。 在此问询之后,我只检查<条码>Cursor.rowcount<>代码,看它是否为1或0,如果是0,那么用户就没有获准完成操作。

我怎么能适当写一下这个问题?

最佳回答

请允许我提出我的对策:

insert into share select id,2 as file_id from files where id=1 and owner=2;

无需<条码>,即无<>。 条款或外国钥匙 份额表,不包括渔获量。

问题回答

我发现,我可以这样做,尽管这不是我希望找到的解决办法。 可在<代码>上添加<0>而不是和(或)对<代码>_id的外在钥匙。 http://www.un.org/Depts/DGACM/index_chinese.htm

insert into share
    values(
        (select id as file_id from files where id=1 and owner=2),
        2
    );

这样,如果使用者不拥有档案,而没有取消和/或外国关键限制将失败,我将在Adhur案中获得例外,那么选择的询问不会回头。

如果有人知道这一问题的真正解决办法,请让我知道,我觉得采用这种做法是 d的。





相关问题
SQL Copy Row for a list, change one column value

I need to duplicate a row a couple thousand times. I need to change one column from the copied row based on a list of ids. Psuedo-code: INSERT INTO MyTable (TabID, Other Columns) VALUES (TabID = (...

Copy mdf file and use it in run time

After I copy mdf file (and his log file) I tries to Insert data. I receive the following message: "An attempt to attach an auto-named database for file [fileName].mdf failed. A database with the same ...

Inserting trigger (SQL 2005)

I have a temp table (question_desc, ans1, ans2, ans3, ans4, correct_ans, marks) with say 10 entries. From this table I have to insert values in two other tables: questions (q_id(auto-generated), ...

mySQL - Prevent double booking

I am trying to work out the best way to stop double booking in my application. I have a table of unique id s each can be sold only once. My current idea is to use a transaction to check if the ...

热门标签