Tutorial: Databases

This tutorial shows us how to empty all the data from a database table

Emptying a Table

Along with deleting rows, say that we wish to delete all our data in our table. This action could be necessary if we input a lot of wrong data into the table, have a table full of redundant data, or we would no longer need to work with this table. Although conserving data is important, having a much more manageable database is prioritized.

For this tutorial, we will be learning how to empty all our data in a data table. Seeing that we have modified our "grocerylist" table so much, we now decide that we would like to start fresh and remove all our data inside that table.

This is a rather simple tutorial as we have no need for any additional objects or actions. We will again start off with connecting our database. Once we connect our database, we will want to call the action EmptyTable(text tableName) using our Database object. EmptyTable() takes in one parameter, a string, which will be the table name we wish to empty. In our case, we will want to pass in "grocerylist" as the parameter. We can verify if our table has been emptied by converting our table into a DataFrame and outputting our frame. To learn more about DataFrames, we can reference this tutorial.

database:EmptyTable("grocerylist")
Empty Actions
Action Description Usage
databaseObject:EmptyTable(text tableName)This action removes all rows in a table. The table will still appear in the database but all rows of data will be gonedatabase:EmptyTable("MovieList")

Congrats! We have learned how to empty a database table. The entire program can be viewed below.

use Libraries.Data.Database.Database
use Libraries.Compute.Statistics.DataFrame

Database database

database:Connect("localhost", "myfirstdatabase", "root", "password")

database:EmptyTable("grocerylist")

DataFrame frame

frame = database:FindAsDataFrame("grocerylist")

output frame:ToText()

Next Tutorial

In the next tutorial, we will discuss joins, which describes understanding JOINS in a database and the different typess of joins.