0
如何添加新用戶(如果尚不存在)?如果數據庫不存在,向數據庫添加新行
這裏是我當前如何將新用戶到數據庫
assert(typeof details.username === 'string');
db.execute("INSERT INTO user (??) VALUES (?)",
[
['username'],
[details.username]
如何添加新用戶(如果尚不存在)?如果數據庫不存在,向數據庫添加新行
這裏是我當前如何將新用戶到數據庫
assert(typeof details.username === 'string');
db.execute("INSERT INTO user (??) VALUES (?)",
[
['username'],
[details.username]
只需改變你的列設置UNIQUE
屬性。
好吧,這聽起來像你的表中只有一列。
所以,如果你想插入一個值,你的列必須設置爲UNIQUE
。 請參閱:http://technet.microsoft.com/en-us/library/ms191166(v=sql.105).aspx
有很多的選擇,一個純SQL並且不需要任何事務檢查它的原子聲明:
INSERT INTO USER
select ? as username where not exists (select 1 from user where username = ?)
請廣告一番解釋和深度,你的答案 –
交鋒一些解釋 –