-1

嗨,我是 SQL 数据库的新手。

我有两张桌子,一张是“Master”,另一张是“Sub”,像这样

Master 
uid(primary key)         f_name            l_name
 1                        fAaa              lAaa
 2                        fBbb              lBbb

第二张桌子

Sub 
tid(primary key)         uid(foreign key)      time           is_free
  1                        1                   1:00AM           0
  2                        1                   2:00AM           1 
  3                        1                   3:00AM           0 
  4                        2                   1:30PM           0
  5                        2                   2:30PM           1   

从这两个表中,我们可以说用户 fAaa lAaa 在凌晨 2:00 是免费的,而在凌晨 1:00 和凌晨 3:00 是免费的。

现在我想像这样更新,对于用户 1(fAaa lAaa),我想删除时间 2:00AM 并想为用户 1 插入新的两个时间,例如上午 5:00 和上午 6:00,而不是我的联接查询更新。

请帮我!谢谢

4

1 回答 1

1

像这样?

DELETE FROM secondtable WHERE uid = 1 AND (time = "1:00AM" OR time = "2:00AM");
INSERT INTO secondtable (uid, time) VALUES (1, "5:00AM"), (1, "6:00AM");

或者

UPDATE secondtable SET time = "5:00AM" WHERE uid = 1 AND time = "1:00AM";
UPDATE secondtable SET time = "6:00AM" WHERE uid = 1 AND time = "2:00AM";

这是一些非常基本的东西,我建议你搜索“sql delete from”、“sql insert into”、“sql update”并寻找初学者教程。

于 2012-10-29T07:35:06.870 回答