SQL Setup Script Magento 2

Some time its necessary to create DB tables and add data to tables. Mageto provides some classes using which you can create DB table structure or add data to tables. Following are the important classes

InstallSchema– This class can be used to setup DB structure when modules is instaled for the first time.InstallData– This class can be used to load the initial data when modules is insttale for the first time.UpgradeSchema– This class can be used to setup DB structure when modules is upgraded.UpgradeData– This class can be used to load the initial data when modules is upgraded.Recurring– This class can be used to run some script that need to executed whenever we issue php bin/magento setup:upgrade irrespective of version change.Uninstall– This class can be used to remove the tables when the module is uintsalled.

All these classes are located at app/code/Vendor/Module/Setup folder. The module install/upgrade script will run when you run the following command line:

php bin/magento setup:upgrade

InstallSchema

The InstallSchema will be run during the module install and its used to cretae DB table structure.