0

How can I insert multiple values in 2 tables? I thought something like this, but that obviously doesn't work:

insert into login as l,
      klantGegevens as k
      (l.password, 
       l.rechten, 
       l.status, 
       k.voornaam, 
       k.achternaam, 
       k.woonplaats, 
       k.postcode, 
       k.telefoonnr)
   values
      ('test',
        1,
        1,
        'niels',
        'jansen',
        'Amsterdam',
        '5993hk',
        0623232323)

EDIT:

 string intoDatabase = "insert into login  (password,rechten,status) values(@password,@rechten,@status) insert into klantGegevens (voornaam,achternaam,woonplaats,postcode,telefoonnr) values(@voornaam,@achternaam,@woonplaats,@postcode,@telefoonnr)";
1
  • you could ue a transaction to make sure that one won't be executed before the other Commented May 21, 2015 at 9:05

1 Answer 1

1

Only in separate commands :

insert into login  (password,rechten,status) 
values('test',1,1)

insert into klantGegevens(voornaam,achternaam,woonplaats,postcode,telefoonnr) 
values('niels','jansen','Amsterdam','5993hk',0623232323)
Sign up to request clarification or add additional context in comments.

4 Comments

@jarlh No, it doesn't :)
should have been a comment :)
Thanks for reply, what's the best way for doing this in c#? See my edit.
@Jenssen You have to do it in two separate commands, maybe in transaction.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.