Execute a Query
First, let’s create our database table.
Open a New SQL File
To begin, open a new SQL file on the database by clicking the new file icon in the DBCode explorer.
Execute a statement
To keep it simple, we will create a “departments” table first, as the “employee” table depends on it. Copy and paste the following code into the new SQL file:
To run the SQL, you can execute via these options:
- Click the execute in the code lens at the top of the editor
- Click the execute icon in the top right
- Use the keyboard shortcut Ctrl/Cmd+D+E
- Right-click and select the “Execute with DBCode” option
Inserting Data
We will insert some sample data into the newly created table. Paste the following code into the SQL File, this time, select the code to execute only this code rather than the whole file.
Run the code using one of the above-mentioned execution methods.
Viewing the Data
To verify that the data was inserted successfully, select the table from the DBCode explorer, which will open a new tab showing the records in the table.
Locate the table in the explorer and click on it to open.
Executing Multiple Statements
Let’s now execute multiple statements at once. These statements will create an “employees” table, insert some data, and perform a select query to join the employees to their departments.
Copy and paste the following code into a new SQL file, or replace the existing code in the current file:
Now, execute the code. If you don’t highlight any content first, you will be prompted to execute the whole document. Select “Yes.”
The results should now be displayed in the DBCode panel at the bottom.
Conclusion
Congratulations, you have successfully created tables, inserted data, and retrieved it.