liveBook · Manning

Data type

As explained in Grokking Relational Database Design

An SQL data type specifies the kind of values that a database column can store and the operations supported for those values.

An SQL data type tells a database what kind of value an attribute or column stores. Choosing an appropriate type helps the database store data efficiently and supports useful queries. section 4.4 section 4.9

Choose a data type by working from the meaning and expected values of an attribute:

  • Examine sample data and the requirements gathered for the subject. section 4.4 section 4.9
  • Identify the proper group, such as string, integer, decimal, or temporal. section 4.9
  • Select the best fit within that group, considering maximum allowed values or spaces. section 4.9
  • Use the selected type when defining the entity’s attributes and implementing the database. section 4.0 section 4.4

Common SQL categories include numeric values such as INT, strings such as TEXT, date or time values such as DATE, Unicode character strings such as VARCHAR, binary values such as BINARY, and miscellaneous values such as XML. In a product table, price can be numeric while manufacturer is a string. section 1.7 section 4.9

Filtering products by typed values

A numeric comparison filters price, while a quoted string filters manufacturer: SELECT * FROM product WHERE price < 30 AND manufacturer = 'Mad Inventors Inc.'; The query combines both criteria with AND and returns matching product rows. section 1.7

SELECT name, description
FROM product
WHERE price < 30;

This listing provides a compact example of using a numeric data type in a WHERE condition. section 1.7

How Grokking Relational Database Design covers it

How deep it goes
Explains type groups and selection from sample data, but defers RDBMS-specific equivalents and exhaustive details.
Examples
Uses product prices and manufacturers, SQL WHERE filters, and serial_number column alterations to demonstrate typed values.
What it assumes
Builds on SQL queries and requirements gathering while teaching attribute-type selection through sample data.
What you can do after
Build it from scratch by assigning suitable types to entity attributes from requirements and sample data.
How it connects
Connects data types with entities, attributes, primary keys, requirements gathering, sample data, filtering, and relational database management systems.

Also explained in

Compare how 18 books explain data type →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Relational Database Design. The section links point to the parts of the book it draws on.