MISC#1 Integer Range, TRUNCATE, Functions, Referential Integrity, SIGNED/UNSIGNED Flashcards
5 INT types
- BIG INT
- INT
- MEDIUMINT
- SMALLINT
- TINYINT
- How bytes of storage does BIGINT have
- Unsigned range for BIGINT
- Signed Range for BIGINT
- 8 bytes of storage
- Unsigned : 0 to 2^62-1
- Signed: -2^63 to
- How bytes of storage does INT have
- Unsigned range for INT
- Signed Range for INT
- 4 bytes of storage
- Unsigned : 0 to 4.3 Billion
- Signed: -2.1 billion to 2.1 billion
- How bytes of storage does MEDIUMINT have
- Unsigned range for MEDIUMINT
- Signed Range for MEDIUMINT
- 3 bytes of storage
- Unsigned : 0 to 16.7 million
- Signed: -8.4 million to 8.4 million
- How bytes of storage does SMALLINT have
- Unsigned range for SMALLINT
- Signed Range for SMALLINT
- 2 bytes of storage
- Unsigned : 0 to 65,535
- Signed: -32,798 to 32,767
- How bytes of storage does TINYINT have
- Unsigned range for TINYINT
- Signed Range for TINYINT
- 1 bytes of storage
- Unsigned : 0 to 255
- Signed: -128 to 127
What is referential integrity?
Ensures consistency/correctness of relationships between tables by enforcing foreign key constraints
What are the four types of referntial integrity?
- RESTRICT
- SET NULL
- SET DEFAULT
- CASCADE
RESTRICT
Rejects whatever if violating the ref integrity
SET NULL
Sets foreign key values to NULL, when records are deleted or updated
SET DEFAULT
sets foreign key values to the default value when records are deleted or updated
function: CONCAT()
used for concatenating multiple strings together into a single string.
EX: SELECT CONCAT(‘Bean’, ‘ ‘, ‘Toast’)
- This produces a result of: Bean Toast
- you specify the string in quotes with any spaces denoted by an empty space in quotes
CASCADE
propagates changes to related records
function: CONV()
used for converting from one number base to another number base
EX: SELECT CONV(‘10’,2,10)
- this produces a result of 2
- You first specifiy in quotes the current number you want to convert, then the current base of the numberm then the base you want the number you want to be converted to
function: SUBSTRING()
used for extracting a substring from a string.
ex: