2017-06-16 7 views
0

値:他のテーブルにレコードを作成します。私は2つのSQLテーブル、ユーザーと主張してい

Users > Id (PK Identity), Name 
Claims > Id (PK Identity), UserId (FK), Name, Value 

を私はすべてのユーザーのための名前=「計画」とValue =「XK」とのクレームを作成する必要があります。

それがクレームのユーザーIDになりますので、私は、各ユーザーのIDを持って:

SELECT Id 
From Users; 

は今すぐIDごとに私がした請求項を挿入する必要があります。

Claim.UserId = User.Id 
Claim.Name = "Plan" 
Claim.Value = "XK" 
+0

あなたは止まったまま。これは、5kポイントの人にとって少し低い質問に見えますか?ロック何十億ものレコードがありますか? –

答えて

2
insert into claims(userid, [name], [value]) 
select userid, 'plan', 'XK' 
from users 
left join claims 
on users.id = claims.userid 
where claims.userid is null 
1

これを試してみてください。

Insert into Claims (userid, name, value)Select id, 'Plan','XK' from Users 
関連する問題