Foreach SQL loop

I am very new to SQL scripts and cannot figure out how to make it specific for each loop. I need to do something like this:

I have tables Sitesand SiteCrawls.

Basically, for each site I need to create a new one SiteCrawl, and the column SiteCrawl Site_IDwill be equal to this site identifier.

How can i do this?

+5
source share
5 answers
insert SiteCrawl
(
    Site_ID
)
select
 s.Site_ID
from Site as s
where s.Site_ID not in (select Site_ID from SiteCrawl)
+12
source
insert into site_crawl (site_id) values (select site_id from site);

, : / SQL, . , : SQL- - , a . , site_crawl site_id . , , , , , :)

: , sql .

, SQL - !

+4

SQL . .

-

insert into SiteCrawl (Site_Id)
select Id from Sites
+3
insert into SiteCrawls (SiteID)
select SiteID 
  from Sites
+1

CREATE TRIGGER tg AFTER INSERT ON `Sites`
FOR EACH ROW
BEGIN
insert into SiteCrawls(Site_ID) values (NEW.id);
END
;
+1

All Articles