How to run SQL Script?
What is SQL Script?
The SQL script is a set of commands that saved as a file in SQL Scripts and it contain one or more SQL statements. We use SQL Scripts to create, run, edit, view or delete the script files.
We must remember the following points while using the SQL Scripts:
- In SQL Scripts, SQL * Plus commands are ignored at the run time.
- There is no any interaction between SQL Scripts and SQL commands in SQL scripts.
- We cut and paste SQL commands from SQL script editor.
- SQL script does not support the bind variables.
Accessing the SQL Scripts
1. First, login to the Workstation.
2. To view the SQL Scripts page, do the following:
- Click on the SQL Workshop icon and drill-out the SQL page.
- Click on the down arrow to the right of the SQL Workshop icon to see the drop-down menu after choosing the SQL Scripts option.
Note: The document used the navigation path (drill-down approach) when we are explaining the navigation for the consistency.
About the SQL Scripts Page
It displays the SQL Scripts that are created by the user. We control the appearance of the page by selecting it from the view list.
The SQL Scripts has three controls:
- Script. It finds the script by entering the partial name or script name in the script field. It displays the rows by selecting from the display list.
- Owner. Find the owner of the script you want to see by going to the owner's name and clicking on the owner's name.
- Opinion. Opinion changes the appearance of SQL Scripts page by selecting the view list.
- Symbol displays every script as an icon that is identified by script name. Click on the Show Results checkbox to show additional results for icons that are determined by the script name.
- Description: The description displays each script in one line. Every line has a checkbox to enable the selection process of script. It allows the script to load script name, script editor, and owner of the script. When the script updated in bytes, the text is linked in the run results, and an icon to enable the script to run.
About the Tasks List
The tasks list is displayed on the right side of the page.
The Task List has these points:
- Task List manages the results and enables the view, search, and display the results.
- Show Quota: The script quota shows the maximum size of result.
- Export enables the SQL repository to import the SQL Scripts in the workspace. The scripts are encoded in a single script and is written in local file system. By default export script is "workspace_name_script / sql".
- Import enables us to import scripts exported by many workspaces.
- The export script accessible on local file system to import.
Use MySQL workbench to run the SQL script.
To open the SQL Script, go to File -> Open
Alternatively, use the shortcut key Ctrl+Shift+O to open the SQL Script.
Import enables the import scripts exported by the workspace or different workspaces. Import only imports the scripts encoded in export scripts created by using export. The export script will accessible on the local file system for importing.
After browsing .sql files, we select the option Reconnect to database, as we have highlighted in the following image.
It asks for a password to connect with MySQL.
Note: Press the OK button twice to connect with MySQL
After the above process, the SQL files tblstudent appears on the screen that we have uploaded before.
After that, we execute the script by clicking on the symbol highlighted in the following image.
After that, we get the following output:
Deleting Script in the Script Editor
To delete the script, follow the steps given below:
- First, click on SQL Workshop and then SQL Scripts on the Workspace home page. The SQL Scripts page appears in the screen.
- Open the script which we want to delete in the Script Editor.
- Click on the Delete button to remove the script from the Script Repository. We are prompted to confirm the action before the script is deleted.
The message Script(s) deleted shows above the updated list of scripts.
Copying a SQL Script
To save the script, we copy the script in the script repository. Follow the steps given below, to copy a SQL Script.
- Click on the SQL Workshop and open SQL Script on the workspace homepage.
- Load the script to be copied to the editor.
- Enter the name of a copied script into script field.
- Click on Save button to save the copy of the script in the script repository field.