beanz Magazine

CRUD

W_Minshuli on Flickr

CRUD is a powerful concept used everywhere in software programming that uses a database.

CRUD is not a league of super heroes or super villains. Instead, CRUD is an acronym for the four basic database-related functions programmers encounter as they create software.

Each letter in CRUD refers to tasks performed with databases:

  • Create or add data
  • Retrieve data
  • Update data
  • Delete data

This acronym likely was created in the 1980s to describe database functionality used by SQL (structured query language) databases. Each letter maps to an SQL operation: INSERT (create), SELECT (retrieve), UPDATE (update), and DELETE (delete). However, these operations also apply to non-SQL databases, for example, MongoDB and BigTable.

How CRUD Works

In practical terms, you likely would have functions or methods to create a data record in the database, retrieve the data record, update a specific data record (usually with the unique ID of the record), and delete a data record (also using the unique ID of the record).

For example, almost all online software applications include the ability for people to sign up to use the application. Here’s how CRUD works with user accounts:

  • When a person signs up, the application creates a database record with their user profile which includes their login information.
  • When they login, another function or method takes their login credentials and retrieves data from the database to confirm they have permission to use the application.
  • If they change their password, the application updates their data record so their next login attempt will validate their credentials correctly.
  • If the person wants to delete their account, a function or method uses their account ID to delete their account data from the application.

CRUD works for every part of any software application which uses a database. For example, an online application to publish content will have user accounts plus the ability to create, retrieve, update, and delete content. It also might have the ability to create, retrieve, update, and delete categories, comments, and other data useful in publishing content.

Often programmers must provide users with forms to allow them to create, retrieve, update, and delete data. This data is then used by the internal functions or methods to interact with the database.

If you write enough software applications, eventually you develop a set of code you can copy and paste to provide user forms and code to interact with the database. Most of your work then becomes a matter of checking the forms are correct for the new application and data is captured then entered or modified in the database correctly. Code to retrieve and delete data also needs to be tweaked to reflect new database table names and similar details. Programmers hired to maintain a software applications know to look for these specific functions or methods in the code base.

To make things even more interesting, code frameworks like Ruby on Rails provide an easy way to access CRUD operations with any database. Instead of coding to interact directly with the database, you pass the data to Ruby on Rails or other framework to handle database interactions. This is a much safer and cleaner way to write software programs that interact with databases.

Beyond CRUD

Some purists would add an S to CRUD for Search. While create, update, and delete affect database data directly, retrieving data does not. Also, retrieving data is used only for updates and deletions. Search also could be limited to database updates and deletions. However, users of software applications often need to search data in the database and see a list of possible search results. The counter argument is that search is a part of retrieving data, not a separate activity.

While CRUD is a common term with programmers, there are other variations beyond SCRUD. For example, some add an L to the acronym for listing large blocks of data, an activity which requires pagination to manage a block of data to display subsets of the data on multiple pages. Pagination requires tracking which subset of unique data to display to the user from the larger block of data.

As a practical matter, programmers who design a new program know they will need functions or methods to create, retrieve, update, and delete data. And programmers who maintain an application know where to go in the code if there’s a bug with the core database functionality. CRUD is both practical and abstract.

While CRUD is not the name of a league of superheroes, it is a powerful concept used everywhere in software that uses a database.

Learn More

CRUD

http://en.wikipedia.org/wiki/Create,_read,_update_and_delete

CRUD, Only When You Can Afford It

A technical article describing the limitations of thinking in terms of Create, Retrieve, Update, Delete in programming.
https://msdn.microsoft.com/en-us/library/ms978509.aspx

Difference Between REST and CRUD

If you have patience, an excellent discussion that highlights how CRUD works in software programming relative to another aspect of programming, REST.
http://programmers.stackexchange.com/questions/120716/difference-between-rest-and-crud

CRUD: Another Acronym Bites the Dust

John Gavin points out another meaning of CRUD, from the nuclear industry, turns out to be untrue.
http://public-blog.nrc-gateway.gov/2015/03/31/crud-another-acronym-bites-the-dust/
https://twitter.com/KidsCodeCS/status/639447984812498944

Also In The August 2015 Issue

In his classroom, he and his students learn together as a community.

These fifth grade students use their genius hours and Trello software to answer tough questions.

Visual storytelling apps are a great way for kids to document and explore their lives.

Raspberry Pi, Arduino, BeagleBone, Micro Bit, Edison, CHIP, and other handheld computers trace their history to board computers used by engineers.

Random Hacks of Kindness, Jr. helps schools and groups host one day hacking events for kids to work with local non-profit groups.

Resources based on teacher recommendations and other sources.

The new Sphero SPRK Edition makes it even easier for teachers, parents, and kids to learn math, robotics, and programming.

Facts, programs, and groups can help girls succeed at STEM careers.

She was in her 30s when she led the team that developed mission critical software used guide the Apollo moon landings.

Learn about and explore the code used to guide Apollo missions.

CRUD is a powerful concept used everywhere in software programming that uses a database.

Links from the bottom of all the August 2015 articles, collected in one place for you to print, share, or bookmark.

Interesting stories about computer science, software programming, and technology for August 2015.

Some thoughts on starting the third year of publishing this magazine and what's new this month.