Getting Started & Your First SQL Query
Master SQL fundamentals with hands-on database exploration
This tutorial uses a demonstration-first approach followed by hands-on exercises. You'll see the concepts explained, then practice them yourself through step-by-step exercises for better retention.
Database Structure Overview
Server Connection
Your database connection represents a server that can contain multiple databases. Think of it as the top-level container for all your data resources.
Database and Schemas
Within each server, databases contain schemas which group related tables together. The 'public' schema is commonly used for main application tables.
Tables and Data
Tables store the actual data with columns defining the type of information. Visual indicators show whether data is numeric, text, or time-based.
Exploring Database Structure
Connect to Database Server
Establish connection to your database server. The connection name often reflects the primary database you're connecting to.
Navigate Schema Hierarchy
Expand the database to view schemas, then explore the 'public' schema to see available tables and their relationships.
Examine Table Structure
Click on table names to view columns and their data types. Icons indicate numeric (123), text (A-Z), and timestamp (clock) data.
Preview Actual Data
Double-click tables to open data tabs and examine real records to understand the content and format of stored information.
Sample Database Tables
VARCHAR(2) means variable-length text with maximum 2 characters, perfect for state abbreviations like 'NY' or 'CA'. VARCHAR(255) allows much longer text fields like addresses or descriptions.
GUI vs SQL Code Approach
Writing Your First SQL Query
Create SQL Script
Open a new SQL editor to create a text file where you can write and execute your database queries.
Write SELECT Statement
Use 'SELECT * FROM tablename;' syntax to retrieve all columns from a specified table. The asterisk represents all columns.
Execute Query
Click the play button or use keyboard shortcuts to run your selected query and view results in the output panel.
Unlike most programming languages that run entire files, SQL editors execute only selected queries. Click on a query to select it, or highlight multiple queries to run them together.
Query Selection Methods
| Feature | Single Query | Multiple Queries |
|---|---|---|
| Selection Method | Click anywhere on query | Highlight all desired code |
| Execution Result | Runs one query only | Runs all selected queries |
| Output Format | Single result tab | Multiple result tabs |
| Use Case | Testing individual queries | Running related query sets |
Essential DBeaver Preferences
Makes SQL keywords consistent with industry documentation standards
Helpful for collaboration and debugging when referencing specific code lines
Prevents horizontal scrolling for long queries, improving code readability
Use Cmd/Ctrl + plus/minus to optimize text size for your display
Access DBeaver preferences through Window > Preferences. SQL formatting options are under Editors > SQL Editor > Formatting, while text editor settings are under Text Editors.
DBeaver Data Loading Behavior
DBeaver loads data incrementally to maintain performance. Imagine querying Amazon's order database with billions of records - you only need a sample to understand the data structure and content.
Saving and Managing SQL Files
Save Your Query
Use Save As to store your SQL code as a .sql file for future reference and reuse.
Organize Files
Create meaningful file names and organize them in project folders for easy retrieval.
Reopen Files
Use Open File to browse and reload saved SQL scripts. Remember you need an active database connection to execute them.
SQL files are fundamentally just plain text files because they contain only text code
This lesson is a preview from our SQL Course Online (includes software) and SQL Certification Online (includes software & exam). Enroll in a course for detailed lessons, live instructor support, and project-based training.
Key Takeaways