Every time when a page loads As @fabian commented out, Every time magento merges the config, Magento will look for any new modules is configured with the system. It uses versioning for check this. If you take a look on the configuration file of any module, you can see the below code there.
1.0.0 is the version number of this module. Magento will keep this version number in it's database. Take a look on the table
core_resource table. There magento holds all module's version number.
Now when a page loads, Magento look for any new modules configured with the system. Magento will use information that is provided inside
app/etc/modules/<Namepace_Modulename>.xml file recognize new modules. Then magento check new module's version number and stores in
core_resource table. Then it will use this version number for checking for valid install/update scripts. Install/update scripts holds sql quries to interact with database. An install script names like this.
install-1.0.0.php. See you can see that it uses version number in it's name. Magento will only execute those files which has a version number equal or higher to the version number that is specified inside of that module's
Once an install script executed based on its version number, it will not execute again. Why ? This is because, magento will check version number in config file with version number that is stored in
core_resource file. If those version number matches, then it means module didn't upgraded, hence it will not look for install/update scripts.
So if you want to use the same install script file of the module again, usually you can use two approaches
Increase the version number inside
config.xml and change the install script name according to that version number. For example, if you increased above module's version number to 126.96.36.199, then you need to change the name of install script to
install-188.8.131.52.1.php. So when a page request takes place, magento will notice that our module's version number has changed and hence look for install script to execute.
Delete entry correspond to our module from
core_resource file and then delete the tables that is created by our modules. Since this make no entry inside data table correspond to our module, when page request takes place, magento will treat our module as a "newbie" and hence execute the installation script.
Normally I use the second method during development. However for you first one would be good.
Refer these links. It will give you much more idea on this. LINK1 LINK2