Foreach in sql with static data
I have 3 tables:
Countries:
Code, Name
Vacances:
id(autoincrement),CountryCode, NameOfCountry, numberOfdays
H开发者_JS百科ow to foreach country insert Row:
countryCode,'Welcome in " + nameofCountry +"!",12
try this
insert Vacances(CountryCode, NameOfCountry, numberOfdays)
select distinct [Code],'Welcome to ' + [Name] +'!',12
from Countries
No need for loops, databases are optimized for SET based operations, take advantage of that
No need for a loop or "foreach"...
INSERT Vacances (CountryCode, NameOfCountry, numberOfdays)
SELECT countryCode, 'Welcome in ' + Name + '!', 12
FROM Countries
精彩评论