question archive   Databases are used to store different kinds of data such as names, currency, text, graphics, etc

  Databases are used to store different kinds of data such as names, currency, text, graphics, etc

Subject:Computer SciencePrice:3.87 Bought7

 

Databases are used to store different kinds of data such as names, currency, text, graphics, etc. Determining the appropriate data type for each attribute is important for database performance, storage size, and conducting accurate analysis on databases. As with other programming languages, SQL supports many data types. However, you will mostly use two categories while writing SQL queries: Characters, and numbers. Consider the following standard SQL data types: Characters char varchar Numbers integer decimal float Different data types could be used for the same attribute. For example, both char and varchar could be used to store "names" in a database. Examine the attributes for the Characters and Numbers data types. Using specific examples, compare data types for each category. For example, why you should choose char rather than varchar or opposite

pur-new-sol

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE

Answer Preview

Answer:

When it comes to varchar verses char is that char is a fixed length data type, while varchar accepts variable length data types.

1. VARCHAR takes up 1 byte per character, + 2 bytes to hold length information.

e.g. VARCHAR(100) = 'Jeff'

would take 4 + 2 = 6 bytes total

 

2. CHAR takes up 1 byte per character.

For Example:

e.g. CHAR(100) = 'Jeff'

would take 100 bytes total

 

As you can see in almost all cases, it is more efficient to use varchar over char, but there are very small cases where char is preferred. For example, if we're sure that our strings will always be a fixed length, such as a phone number, then it will be more efficient to use CHAR.

When it comes to numeric data types: of course we have to consider what type of information we are dealing with, if we're dealing with numbers with decimals we might use FLOAT, DOUBLE, or DECIMAL. DECIMAL's are for when we are absolutely sure if the precision of every decimal is the same. If the number doesn't have decimals, then we might use TINYINT,  SMALLINT, MEDIUMINT, INT,BIGINT etc., based on how big (or small) our number is.

The Last big data type of Date and time data types:

They are mostly variations of DATETIME formats. They follow this format: '9999-12-31 23:59:59'

Timestamp has a unique attribute in that it's value changes with the timezone.