How to Build a SQL GUI in 5 StepsBy: Ronan McQuillanSep 22, 2022 | 17 minutes readSQL is a powerful database query language that can be used to unlock valuable insights stored in databases. But SQL can be difficult to learn and use, particularly for non-specialists.Thatâs where a SQL GUI (Graphical User Interface) comes in handy.SQL GUIs are useful for developers and non-developers alike. They provide intuitive interfaces to interact with the database without writing SQL commands. You can visually interact with tables, rows, fields, searches, and more, without any specialist knowledge.Thus, you donât need to worry about the right code syntax to get the data you want to see. You just use the GUI components, like you would with any other app.They can cater to advanced users as well. With them, you can quickly perform simple tasks. And if you want to write SQL code anyway, itâs always possible to do it.Another benefit of a dedicated GUI is that you can have a single tool to load data from different databases with completely different architectures. Therefore, with a single tool, you can see all your MySQL, MariaDB, and even Oracle databases, wherever you are.The bad news is that buying a SQL GUI might not be an easy decision. There are many things to consider, such as licensing, access control, user volumes, app installs, and custom workflows.But you can solve this with low-code development.Itâs possible to build your own SQL GUI in just 5 steps. Using Budibase, you can create a tool that does exactly what you want it to, that loads all your data, for unlimited users and with web access.This is the beauty of low-code development.The truth is, you donât even need the full 5 steps. If you just want a simple CRUD interface, you can do it with just steps one and two. But today, weâre going to look at how to create something a little more sophisticated.Here is a quick overview of the steps to build your SQL GUI app:Create your app and connect to your database.Create your CRUD interface with one click.Custom DB connections to read, write and delete data.Custom screens to see and filter all your tables.Forms to edit data from any table.Letâs get started!Does SQL have a GUI?SQL is a standard language that lets you store, manipulate and retrieve data in databases. It doesnât have a GUI in itself, but there are many applications you can use for that.They come in a vast range of options and prices, and you can even build your own GUI for free, by following this tutorial.In case you want to check out what options there are out there, here is a list of off-the-shelf solutions:DBeaver.SQLyog.DataGrip by JetBrain.DbVisualizer.DronaHQ.MySQL Workbench.OmniDB.DataGrip.HeidiSQL.What is the best GUI for SQL?The best GUI depends on your needs. Some are more popular, due to how they are distributed. For example, phpMyAdmin is pretty ubiquitous.Others cater to very specific needs.Here are some points to consider when you pick a SQL GUI (or if you build your own):License cost - be it one time, monthly or yearly.Licensing limitations - number of users, number of instances.Local or web-based - some are accessible online, others only work as desktop installations.Databases supported - some work with a specific database, and others can work with multiple databases.Ease of use - how complex the interface is.Customization - if itâs possible to add new features to it via plugins, or even editing the source code.Reliability - if the tool works all the time or if it breaks.How do you create a GUI?You can create your SQL GUI using Budibase. There are actually two methods to interact with your databases, and youâll learn both:Using the one-click interface to generate CRUD pages for a table.Using custom connections, queries, and a little bit of custom code to make a flexible interface that loads any table from a database connection.The end result is something like this:This is the main app page. In it, you can select the tables, filter data, add new records, and edit rows. The add new/edit screen looks like this:The form is the same for both the new row and edit options. The only difference is that one creates a new row, and the other updates a current row.In addition, there is the App Settings page:The settings page is where you add your DB tables. Using this method your end users donât need to edit the Budibase app to add new data. They can just insert them using this screen.If you take a closer look, it is quite similar to the home screen. The difference is that the settings screen is created using the auto-generated pages, while the home screen is custom-built.This may seem like a small difference in terms of end result, but they have different use cases and capabilities.Itâs worth mentioning that weâre not going to dive too deep into security and user-control today. If you have a lot of users or critical data, make sure to include protections against SQL injection and proper user controls in your pages and queries.1. Create your app and connect to a databaseTo get started, you can create a free Budibase account.Once thatâs done, itâs time to connect to your data source . In our demo, we are using a MySQL database.Add the connection details on the interface:Make sure you have whitelisted the Budibase IP in your server. Otherwise, even with the right credentials, you wonât be able to connect.Next we need to store our Appâs settings. You can use one of your tables to do it, but another option is to use Budibase DB.In our demo app we have a table called â_app_setting_sâ with these columns:Table_name.ID.Title.Value.Youâll use this table to select which columns from the MySQL tables correspond to this format. This allows us to use a single table with a fixed structure to display data from any table we want.For example, in the MySQL tables we have these tables and columns:Posts:id,title,content,date,Settings:id,settings_key,value.Therefore, we need to tell Budibase, which attributes from each of the tables go into each of the columns we have available.These are the mappings:2. Generate a SQL GUI automaticallyIf you just need a simple GUI, you can create it automatically with Budibase. Letâs do this with the App Settings so you can use this method for your tables.Go to the Design tab, select the screens menu, and hit add screen.Then select the âAutogenerated screensâ option and pick the app_settings table.This is what you should see:And thatâs all you need for a basic SQL GUI. You can repeat this process with all tables in case you want just these functions.In our example, weâve changed the app formatting a bit too. You can do this in the âThemeâ section:We picked a dark theme and a CSS gradient for the header background. You can add any valid CSS background values in here, including simple colors or complex values, such as gradients and even background images.Now letâs see how you can spice up your SQL GUI with a single screen that loads multiple tables.3. Custom database connections and queriesIf you have a lot of tables to manage, maybe manually creating a CRUD interface for each of them isnât the best option. Itâs possible to create your own interface that loads tables and databases automatically.For your end users, this might be an easier option, since they can add new tables and databases without editing the app itself.They just need to add the tables in a settings table. As long as your current DB connection has the right capabilities to access data, youâll see it automatically.Now, as for how you can create this dynamic SQL GUI, there are a few important elements:The DB commands - they depend on your database, so youâll need a screen for each of your database connectionsThe tables schema - here we use a mapping method so all tables respond to the same schema. There are other ways of doing this thoughThe tricky part here is to take a user input (tables options) and add it to your queries dynamically. This is hard because SQL usually doesnât allow functions or variables in table names.So you canât just use a command like SELECT * FROM {{ table }}, because this binding is treated like a plain string (wrapped by single quotes).Check out our guide to database schemas for more information.Some DBs such as MariaDB have a handy command for this, EXECUTE IMMEDIATE. It allows you to send a SQL command with variables or anything else you need.If your DB has this command, then you can just use something like this in your queries:EXECUTE IMMEDIATE âCONCAT ( ‘SELECT * from â, {{ table }} ) âBut since we are using MySQL we need something else. If you look closely, the EXECUTE IMMEDIATE command is actually just a shorthand for this:PREPARE stmt from âCONCAT ( 'SELECT * FROM â, {{ table }} ) â; EXECUTE stmt; DEALLOCATE PREPARE stmt; And this is actually possible with MySQL. You just need access to your DB (using PHPMyAdmin or similar) and you can create a procedure there with something like this:BEGIN SET @q = query; PREPARE stmt FROM @q; EXECUTE stmt; DEALLOCATE PREPARE stmt; END Now you are ready to perform the same actions as you could do with MariaDB, with a slightly different syntax. This is how we do it:CALL execute_immediate( âCONCAT ( ‘SELECT * from â, {{ table }} ) â )Thatâs it, you are ready to run any type of command that you need using variables.Head over to the âDataâ section, and letâs create three queries. One to select data, the second to edit/add data, and the last query to delete data.Here is the setup for the variable_select query:Then use this SQL command for the fields:CALL execute_immediate( CONCAT ( ‘SELECT ‘, {{ID}}, ’ as “ID”, ‘, {{Title}}, ’ as “Title”, ‘, {{Value}}, ’ as “Value” FROM ‘, {{table}} ) )This command takes the bindings and use them to build the query. Notice how everything is variable, including the table name and the column names, which are mapped to ID, Title, and Value.Also, notice that we are mapping the table columns to standard names, ID, Title, and Value. This allows us to use a single table and a single form to view and edit all of them.Make sure to use this transformer:return data[0] By default, when you execute a stored procedure, MySQL returns some extra data that you donât really need. So you can just read the first value of the data array (data[0]) to get the query results.You can run this query and save it.Next, thereâs the insert/edit query.This time, the entire command is dynamic, given that we use the form fields to create it.Here is the setup:Lastly, thereâs the delete query. Here is the setup for it:Now your queries are ready. Letâs load them up in your screens.4. Load any table from your databaseIf you want to load your tables dynamically, you need a few data points. Each of these can be pulled with the data provider component in Budibase.This should be the hierarchy of your data points:Load all possible tables (from the Budibase DB app_settings table),Dropdown for the user to pick their desired table,Load the selected tableâs mappings (ID, Value from app_settings)Load the table data sending the correct bindings (table name, id, value) to the variable_select MySQL query.If you want to implement this screen, you just need to follow that structure. This is your final element tree:The first component is the main container. This is used to hold all of your other components.Then thereâs the first App Settings Provider. It has no settings, and it just loads data from the app_settings table.Inside of that provider youâll add the Select Table form. All form components require a form to be their parent, otherwise they wonât work. This form is there just to make the dropdown work, you donât need to change its settings.Next thereâs the table options picker. We are using these settings for it:When your user picks a new option, your table should change. You can do this by creating an app state. This is just a way to store variables temporarily in your app, based on user actions. To do that, use this option for the OnChange action of the button:In addition, we want that dropdown to automatically select the current table. But when users first load your app there will be no selection. Thus, you can select the default value of that field to be a JS function, like this:var ret = $("State.selected_table"); if ( ! ret ) { ret = "posts"; } return ret; The next component to implement is the Selected Table Meta, which loads the metadata for the current user selection. It is a data provider just like the first one, loading data from the app_settings table.The difference is that now we add a filter to it. You can set it to load items with table_name equals {{ State.selected_table }}.Then add a repeater to expose the fields of that data provider. And inside that repeater itâs finally time to load the table data.As the name suggests, the Selected Table Data Provider loads data for your selected table using the variable_select query. But you need to set the correct bindings to it to make sure it loads the current tableâs data and maps it:Now you can add a dynamic filter so users can view only what they want from that table.The next component is the âadd newâ button. It is a simple button that has a ânavigate toâ action when users click on it:You can add your table inside the selected table data provider, and add a button inside of it to edit rows. Just like the add new button, the edit button simply navigates to another screen. But this time we use the current row as part of our URL:These URLs may look weird, but they are just a method to pass data to Budibase. In short, you are telling it to load the /edit/ screen with the row ID, or with zero, if itâs a new item. Then that screen handles these numbers as a variable.Letâs see how to do it in the next section.5. Insert, edit, and delete dataJust like the home screen, the edit screen requires some data points to work correctly.First, you need a URL variable to get which item is being updated. To do that, use /:id in your route. For example, our demo uses /edit/:id.Therefore, if you visit myapp/edit/130, then the id variable is set as 130. This works not just for numbers. If your app requires text-based variables, you can use them, for example, /edit/myitem. In this case, the id variable is myitem.Itâs worth noting here that this will only work if the variable you bind to your URL is unique. Weâd normally use ID, because this is an automatically generated attribute thatâs unique to each individual row.In terms of data points, this is what you need for the edit screen:Item ID (URL),Current table (app state),Table mappings from app_settings,Add new item form inputs,Data provider to load the default values for the edit mode,Edit item form inputs,Item update state (for the success message).You can copy the following component tree:Again, you have a main container to organize all your components.Then, inside of it thereâs the App Settings Provider. It loads the app_settings table. This time, we are filtering it by table name equal to this function:var state=$("State.selected_table"); if ( state ) { return state } else { return "posts" } This function returns either the currently selected table or the default table, which in our case is posts.The Add New container should only be visible if we are adding a new item. To do this, add a new container and set the conditions to Hide component if {{ URL.id }} Not equals 0. So, if the url is anything other than /edit/0, we are editing an item.Therefore, the add new option shouldnât be visible.The Add New form is just a placeholder for the components. This time, the entire action is accessed in the Add New button. You can insert the headline and text fields, then use this set of actions for the button:Update State - Set the app state updated_rows to zero (so the success message is hidden).Execute Query - the variable_update query, with settings for the âinsertâ mode and using the form values along with the bindings coming from the app_settings.table = INSERT INTO {{ State.selected_table }}fields = (`{{ App Settings Provider.Rows.[0].[Title] }}`, `{{ App Settings Provider.Rows.[0].[Value] }}`) VALUES ( “{{ Add New Form.Fields.New Title }}”, “{{ Add New Form.Fields.New Value }}” )Where = ââImportant: Make sure to set the where as â â, an empty space, so the default value wonât be used.Update State - Set the app state updated_rows to one to display the success messageThatâs all you need for the âadd newâ form. The edit form is quite similar, the main difference is that you have default values for the form items.Add a âview rowâ data provider. In it, you can load the variable_select query and use the bindings coming from the App Settings Provider:table = {{ App Settings Provider.Rows.[0].[table_name] }}ID = {{ App Settings Provider.Rows.[0].[ID] }}Title = {{ App Settings Provider.Rows.[0].[Title] }}Value = {{ App Settings Provider.Rows.[0].[Value] }}In addition, set the conditions for the data provider to âHide Componentâ if {{ URL.id }} Equals zero. Therefore, if we are adding a new item (/edit/0), this entire block is hidden.Next, add a repeater to expose the data provider fields so they are easier to work with.Then, add a new button. This is the button to delete items. You can use this Custom CSS:position: absolute; right: 0; Now you can add three actions when that button is clicked:Execute the variable delete - Make sure to require confirmation and use these bindings:table = {{ State.selected_table }}ID = {{ App Settings Provider.Rows.[0].[ID] }}IDValue = {{ New Repeater.variable_select.ID }}Update State updated_rows to zero, so the next time you load the edit page this message is hidden.Navigate to /home.Then, you can add a headline with the value {{ New Repeater.variable_select.Title }}This is the same value that youâll use in the default value for the title text input. For the value text input, you can use {{ New Repeater.variable_select.Value }}.Like the previous form, the update form is just a placeholder. The actions are in the update button. The logic for this button is quite similar to the previous one. Here are the actions youâll run:Update State updated_rows = 0Execute Query variable_update:table = UPDATE {{ State.selected_table }}fields = SET {{ App Settings Provider.Rows.[0].[Title] }}="{{ Update Form.Fields.Title }}", {{ App Settings Provider.Rows.[0].[Value] }}="{{ Update Form.Fields.Value }}"where = WHERE {{ App Settings Provider.Rows.[0].[ID] }}={{ New Repeater.variable_select.ID }}Update State updated_rows = 1Thatâs it, your form is ready to edit items.The finishing touch is a message to let users know that the add new / update action worked. You can add a container and set its conditions to Show component if {{ State.updated_rows }} Equals to 1.You can add a green border around it, and a headline component with your update message.How to build a SQL GUIWeâve only scratched the surface of what is possible with SQL GUI development, we hope you are now inspired to create your own.In this article, we have explored many different techniques, such as autogenerated screens, dynamic queries, different data loading methods.Only the sky is the limit when it comes to what you can do following the 5 steps from this tutorial.We hope youâve enjoyed, and see you again next time!Check out our guide to building database GUIs .To see more of what Budibase can do, why not check out our 50+ free, deployable app templates .