4D Database Tutorial: A Complete Guide
A 4D database tutorial begins with four main objects: tables, fields, forms, and methods. 4D is a and application development platform from 4D SAS, first launched in 1984, storing data in a proprietary “.4DD” structure file tied to a compiled or interpreted application layer. Developers define tables, build forms, and attach code in one integrated environment.
4D occupies an unusual place in the tooling landscape. It is a combination relational database engine, rapid application development environment, web server, and low-code-ish form designer. This combination is why small teams adopt it: one product covers storage, business logic, UI, and deployment.
The engine is relational in the classic sense: tables, primary keys, associated tables and relations defined in the structure. It is not SQL first like PostgreSQL or MySQL, although 4D supports SQL via its SQL engine and Begin SQL / End SQL commands. Most daily tasks use 4D’s own language (historically called 4D Language, now simply 4D code), which is closer to a scripting language than SQL. This 4d database tutorial approach helps beginners understand the tool’s versatility.
Two architectural facts matter early on:
- Structure versus data. The structure (tables, fields, forms, methods) resides in a
.4DC/project file in modern versions; the data is in the.4DDdata file. In 4D 20 and later, projects are stored as a folder of text files, making version control with Git practical. Older.4DBbinary structures are more difficult to diff. - Client-server versus single user. A single-user deployment runs everything on a single machine. The client-server separates the 4D Server (data + business logic) from the 4D Client (UI). The same structure supports both, but network roundtrips change how you need to write loops.
If you’re coming from Microsoft Access, the mental model transfers well. If you’re coming from a web stack, expect to unlearn some habits: 4D forms are stateful and event-driven, not request-response.
Step 1: Install and Create Your First Structure
Download 4D from the official 4D website (4d.com) to begin this 4d database tutorial. You will typically choose between 4D (the full development environment) and 4D Server for deployment. There is a free local development mode for learning, but deployment to production requires a license: check the current license terms directly, as they change from release to release.
Related: — A spreadsheet-simple interface sitting on top of a real relational database, with automations, views, and shareable interfaces..
Creating a project:
- Launch 4D and choose New > Project.
- Name the project and choose a folder. Modern 4D creates a project folder containing
Project/Sources/with your structure as text files. - The Structure Editor opens. This is your schematic canvas.
The structure editor is where you add tables. Each table is given a name, a set of fields, and optionally an automatically generated primary key. 4D’s convention is to prefix field names by type — ID_, Name_, Date_, Amount_ — although this is a matter of style and not a requirement. Consistency pays off later when you scan 200 fields.
Field types you’ll use most: Text, Alpha, Integer, Longint, Real, Date, Time, Boolean, Picture, BLOB, Object, and UUID. The Object type stores JSON-like structured data and is the modern choice for flexible attributes. UUID fields are the recommended primary key type for new tables because they avoid collision and renumbering issues with auto-incremented integers in distributed or merged data.
If you are shopping: — A that plugs into the wider Zoho suite and prices per user rather than per app..
Step 2: Design Tables and Relations
Schema design in 4D follows relational normalization rules, with a particularity specific to 4D: relations are declared graphically and involve automatic behavior. This is a key part of any 4d database tutorial.
To create a relationship, drag the primary key field from one table to the foreign key field of another in the structure editor. 4D draws a relationship line and allows you to configure:
| Relation setting | What it controls | Practical effect |
|---|---|---|
| Automatic relations | Whether 4D auto-loads related records | Convenient for forms; can cause hidden queries in loops |
| One-to-many vs many-to-one | Direction of the link | Determines which side holds the foreign key |
| Related table name | The accessor name in code | Becomes the property you reference, e.g. [Invoice]Customer |
| Deletion control | Cascade, restrict, or nullify | Prevents orphaned child records |
A concrete example: an Invoice table with a CustomerID field linked to Customer.ID. In the code, [Invoice]Customer.Name walks the relationship. This is elegant – and dangerous in a loop over 10,000 invoices, because each access can trigger a lookup. The fix is to deliberately use RELATE MANY / RELATE ONE, or to load the related data into a collection first.
Compromise to decide early: Normalized tables with declared relationships give you referential integrity and simple code, but cost performance on large reads. Denormalized tables with embedded object fields are faster to read but push integrity checks into your own code. For most business applications for small teams, normalize the transactional core and denormalize the reporting tables.
Step 3: Build Forms
Forms are the user interface layer of 4D and they come in several types: detail forms (one record), list forms (multiple records), input forms, output forms, and project forms (not linked to a table). The form editor is a drag-and-drop canvas with a list of properties. This is a key part of any 4d database tutorial.
Key concepts when creating a form:
- Data source. Each form is linked to a table, or to a variable/expression for project forms.
- Widgets. Fields, buttons, checkboxes, drop-down lists, list boxes and hierarchical lists. List boxes are the workhorse for displaying related data and are much more powerful than a simple grid.
- Object Methods. Right-click any object and attach a method. The method runs on events like
On Load,On Clicked,On Data ChangeandOn Validate. - Form Methods. The form itself has a method for form level events such as
On LoadandOn Unload.
A handy template for a customer detail form: place customer fields, add a list box linked to a selection of invoices from that customer, and place a button that executes a method to create a new invoice. List box selection is query or relation driven, and refreshing it after insertion keeps the UI honest.
Warning: 4D forms are stateful. A form contains a current record and a current selection. Mixing form-level state with background processes is the most common source of confusing bugs for newcomers. Keep long-running jobs in a separate process and publish the results back.
Step 4: Write Methods and Business Logic
In this 4d database tutorial, the 4D code is broken down into methods, which come in several versions:
- Database methods — triggered by database events (startup, shutdown, on backup).
- Table methods — triggered by record events (on save, on delete).
- Form and object methods — triggered by UI events.
- Project Methods — your reusable functions, callable from anywhere.
- Triggers: Execute operations before/after record operations, ideal for audit trails.
Modern 4D code supports classes and the “This” keyword, allowing you to write object-oriented code rather than just procedural. A minimal project method looks like:
// Project method: CreateInvoice
// $1 = customer ID (UUID)
C_OBJECT($invoice)
$invoice:=ds.Invoice.new()
$invoice.CustomerID:=$1
$invoice.Date:=Current date
$invoice.Status:="Draft"
$status:=$invoice.save()
The ds object (data store) is the modern ORM style access layer introduced with ORDA (Object Relational Data Access). ORDA lets you work with entities and entity selections instead of traditional selections, and supports query chaining, computed attributes, and client-side entity selections that reduce server round trips. For new developments, ORDA is the recommended route; Classic commands like “QUERY” and “CREATE RECORD” still work and appear in older codebases.
How to decide: Use ORDA for new code and anything that benefits from readable and chainable queries. Keep classic commands where you need very tight loops over large selections, because classic selections can be more memory efficient in some server-side scenarios. Measure rather than assume.
Step 5: Value Lists, Queries, and Reporting
Value lists populate drop-down lists and list boxes with a controlled set of choices. 4D supports several types of lists:
- Static Lists — hard-coded values, ideal for statuses and flags.
- Table Lists — values extracted from a reference table, ideal for customers, products and categories.
- Hierarchical lists — parent/child values, useful for chart-of-accounts or category trees.
For queries, ORDA’s query() accepts a formula string with placeholders, which avoids injection issues and reads clearly:
$sel:=ds.Invoice.query("Status = :1 AND Date >= :2"; "Open"; $startDate)
Reporting in 4D uses the Quick Report editor for simple tabular output and the 4D Write Pro area for rich documents. Write Pro is a word processing object embedded in a form; you can merge data into a template and export it to PDF or DOCX format. For anything complex, generating HTML and rendering it to a web area is often quicker to create and easier to style. This concludes this section of the 4d database tutorial.
Step 6: Deploy and Maintain
Deployment options shape your architecture in this 4d database tutorial:
- Single user: application and data on a single machine. The simplest, no concurrency.
- Client-server — 4D Server contains data and business logic; 4D Client connects. Ideal for LAN teams.
- 4D Web Server — 4D directly serves REST endpoints and web pages. ORDA exposes automatic REST access to your data store, which means you can create a web interface on the same schema.
- 4D for iOS / Android — mobile clients generated from your structure.
Backups are built-in: 4D Server can schedule automatic backups and maintain a journal (log file) for point-in-time recovery. Enable the journal before going live, not after. Test a restore on a copy of the data: An untested backup is a hope, not a plan.
Version control: With structures in project mode, commit the Project/Sources/ folder to Git. Exclude the data file and the DerivedData folder. This is a real improvement over the binary era and worth adopting from day one.
Common Mistakes and How to Avoid Them
Skipping primary key discipline. Each table needs a stable and unique primary key. UUIDs avoid renumbering issues caused by auto-incrementing integers when records are deleted or merged.
Putting business logic into form methods. Form methods should handle the user interface. Move rules into project methods or classes so they can be reused by web endpoints, imports, and scheduled tasks.
Ignoring the journal. Without it, a crash while writing can leave the data file inconsistent. Turn it on.
Looping over relationships. Accessing [Table]Related.Field inside a large loop multiplies queries. Pre-load with ORDA or use “RELATE MANY” once.
Treating 4D like SQL. You can use SQL, but 4D idiomatic code is generally shorter and better integrated with forms and events. Learn the native language first as part of your 4d database tutorial.
Learning Path and Resources
Start with the official 4D documentation and the 4D Developer Blog, which covers ORDA, Write Pro, and version-specific changes. The 4D community forum is active and responds well to specific questions. For relational design fundamentals that apply regardless of platform, the Wikipedia article on relational databases and SQL entry provide useful information on query normalization and semantics.
A realistic learning sequence: create a single table contact manager, then add a related table and list box, then add a list of values and a query form, then deploy a client-server. Each step introduces a new concept without overwhelming you.
Key Takeaways
- 4D combines a relational database, IDE, form designer, and web server in a single product, suitable for small teams that need to quickly deliver a custom business application. This 4d database tutorial highlights its efficiency.
- Define tables and relationships in the Structure editor, create screens in the Form editor, and attach logic via methods and triggers: the four objects that make up every 4D application.
- ORDA (
ds, entities, entity selections) is the modern data access layer and the recommended choice for new code; classic commands remain valid in legacy projects. - Use UUID primary keys, enable the journal, and commit project-mode structures to Git from the start to avoid painful migrations later.
- Keep business logic out of form methods and preload related data instead of walking relations inside large loops.
Sources & Further Reading
- Relational database — Wikipedia: A relational database (RDB) is a database based on the relational model of data, as proposed by E. F. Codd in 1970. A Relational Database Management System (RDBMS…
Frequently Asked Questions
Is 4D a SQL database?
4D is a relational database with its own native language and an integrated SQL engine. You can issue SQL statements via Begin SQL / End SQL, but most 4D development uses ORDA or classic 4D commands rather than SQL. The underlying model is relational (tables, keys, and relations), so SQL concepts transfer, even if the syntax you write every day doesn’t.
Do I need to know programming to use 4D?
Basic programming knowledge is very useful, as forms and business rules are linked to 4D code. That said, 4D’s built-in form editor and wizards allow you to create a functional data entry application with minimal code. Citizen developers typically start with forms and value lists, then learn the methods they need for custom behavior. For those starting out, a 4d database tutorial can be helpful.
What is the difference between ORDA and classic 4D commands?
ORDA is an object-oriented access layer built around a data store (ds), entities and entity selections, with chainable queries and support for client-side selections. Classic commands such as QUERY, CREATE RECORD and MODIFY SELECTION work on classic selections and current records. ORDA is the recommended approach for new development, while classic commands remain common in older codebases.
Can 4D applications run on the web or mobile?
Yes. 4D includes a built-in web server and ORDA can expose REST endpoints over your data store, so a browser front-end can communicate with the same schema. 4D also offers mobile client generation for iOS and Android. The tradeoff is that web and mobile clients must pay close attention to authentication and the amount of data returned by each request.
How do I back up a 4D database safely?
Enable the journal (log file) in 4D Server so you can recover to a point in time and schedule automatic backups rather than relying on manual copies. Always test a restore against a copy of the data before you need it in an emergency. Keep the structure under version control separately from the data file, as they change at different rates.
Is 4D suitable for a small business app?
4D is designed for exactly this scenario: a small team creating a custom business application with forms, reports, and a relational schema. It scales to client-server deployments and web access without changing the core structure. The main considerations are licensing cost and the smaller talent pool compared to mainstream web stacks, so long-term maintenance and build speed must be weighed.
P.S. A few readers have asked which relational database platform we actually reach for — it's Claris FileMaker Pro; if you want the current details.
Frequently asked questions
Is 4D a SQL database?
4D is a relational database with its own native language and an integrated SQL engine. You can issue SQL statements via Begin SQL / End SQL, but most 4D development uses ORDA or classic 4D commands rather than SQL. The underlying model is relational (tables, keys, and relations), so SQL concepts transfer, even if the syntax you write every day doesn't.
Do I need to know programming to use 4D?
Basic programming knowledge is very useful, as forms and business rules are linked to 4D code. That said, 4D's built-in form editor and wizards allow you to create a functional data entry application with minimal code. Citizen developers typically start with forms and value lists, then learn the methods they need for custom behavior. For those starting out, a 4d database tutorial can be helpful.
What is the difference between ORDA and classic 4D commands?
ORDA is an object-oriented access layer built around a data store (ds), entities and entity selections, with chainable queries and support for client-side selections. Classic commands such as QUERY, CREATE RECORD and MODIFY SELECTION work on classic selections and current records. ORDA is the recommended approach for new development, while classic commands remain common in older codebases.
Can 4D applications run on the web or mobile?
Yes. 4D includes a built-in web server and ORDA can expose REST endpoints over your data store, so a browser front-end can communicate with the same schema. 4D also offers mobile client generation for iOS and Android. The tradeoff is that web and mobile clients must pay close attention to authentication and the amount of data returned by each request.
How do I back up a 4D database safely?
Enable the journal (log file) in 4D Server so you can recover to a point in time and schedule automatic backups rather than relying on manual copies. Always test a restore against a copy of the data before you need it in an emergency. Keep the structure under version control separately from the data file, as they change at different rates.
Is 4D suitable for a small business app?
4D is designed for exactly this scenario: a small team creating a custom business application with forms, reports, and a relational schema. It scales to client-server deployments and web access without changing the core structure. The main considerations are licensing cost and the smaller talent pool compared to mainstream web stacks, so long-term maintenance and build speed must be weighed.
Try FileMaker Free for 45 Days
The long-running relational database platform for teams that need custom apps on desktop, web, and mobile from a single file.