Rails: A little summary about data types

At first

** Day 17 of Calendar Planning 2020 ** It's been about 3 months since I started studying programming, so I will leave a note of what I learned in the article as an output. I would be happy if I could help anyone entering the world of programming. Please let me know if there are any words that are wrong, wrong, or misunderstood ^^ I'm sorry if it's hard to read the words for a long time. I will do my best to get used to it little by little.

Rails: Let's summarize the data types

Here I have summarized the database tables. That's where the column came in. The data type has the role of limiting (conditioning) the column.

For example Wouldn't it be a bit of a problem if the amount of money was entered on an online shopping site? Normally, I would like to enter only the price "2980", but if I do it without restrictions, only the "special price" will be displayed instead of the price due to mistakes on the store side and I do not know the essential price. I can think of it. Besides, if you want to pay the total amount but the characters are included, it will not work properly and it will be annoying to customers.

It's a little difficult to understand, but you can prevent the data that you don't originally want from being included.

Introducing typical data types

Data type Restricted content
integer Numerical value (integer)
decimal Numerical value (highly accurate decimal number)
float Numerical value (floating point number)
string letter(~(Short character string up to 255 characters)
text Character (long string)
date date
datetime Date and time
time Times of Day
timestamp Time stamp
binary binary
boolean Authenticity

There are other columns that can be set in addition to the data type.

AUTOINCREMENT

A function that automatically assigns numbers in sequence. Often used for ID. Accounts and posts are assigned in order of creation, starting from 1.

NOT NULL

A function that prohibits blanks. It's a good idea to add this to items that aren't empty when you save them! For example I don't want to be registered with the password for creating an account, so I can add it If you want your blog to have a title, you can add it to the column corresponding to the title.

DEFAULT

Ability to set initial values. When the record is registered, the column value is automatically entered and registered.

UNIQUE

This is a function that prohibits duplication. It is used when you want to prohibit registration with the same e-mail address or when you have duplicate passwords.

I think there are others, so if you are interested, please check it out.

Finally

When creating columns in this way, you can limit them at the same time and set rules to prevent erroneous operations when you start operating the application. This first design is quite important, isn't it?

Recommended Posts

Rails: A little summary about data types
A memorandum about table data types and commands (Rails)
A little summary about typesafe config
[Rails] I learned about database data type types!
About Rails 6
[Personal memo] I learned a little about modifiers
Rails: A brief summary of find, find_by, where
About Rails routing
A summary of only Rails tutorial setup related
About Java data types (especially primitive types) and literals
[Rails] About ActiveJob ,!
(Ruby on Rails6) Creating data in a table
A note about the Rails and Vue process
rails db: 〇〇 Summary
About Rails controller
About RSpec (Rails)
A brief summary of Rails association options (foreign_key, primary_key)
I want to use a little icon in Rails
About Java basic data types and reference type memory
Extract all data about a particular user with ActiveRecord
Set up a Db2 DB container and insert a little data
[Rails] About migration files
[Rails 6] About main gems
Q & A about JDK
[Rails] About active hash
[Rails] devise-related routing summary
[Rails] Migration command summary
About rails application server
About custom data attributes
MEMO about Rails 6 series
[Rails] rails db command summary
rails error resolution summary
[Rails] About Slim notation
[Swift] About enumeration types
Personal summary about Java
[Java] Main data types
[rails] About devise defaults
Rails: About partial templates
About rails strong parameters
[Beginner] About Rails Session
Java basic data types
A note about the seed function of Ruby on Rails
[Rails] Implemented a pull-down search function for Active Hash data
How to deploy a Rails application on AWS (article summary)