CREATE TABLE Event (EventID int,
Code varchar(3),
Description varchar(30),
SeatsAvail
int,
TypeFlag int,
Rating decimal(4,2));
A varchar data type stores variable-length data, rather than fixed-length data as required for the Code column in this scenario. The SeatsAvail column does not minimize storage because it is defined as an int data type. An int requires four bytes of storage. In this scenario, a tinyint would be sufficient. The TypeFlag does not minimize storage because it uses an int data type. Because only two possible values need to be stored, a bit could represent this with less storage. DBA/Developer should not use the following CREATE TABLE statement:
CREATE TABLE
Event (EventID int,Code char(3),
Description
varchar(30),SeatsAvail
smallint,
TypeFlag bit,
Rating decimal(3,2));
The SeatsAvail
column does not minimize storage because it is defined as a smallint data type.
A smallint data type requires two bytes of storage and can hold values between
-32,768 and 32,767. Atinyint uses one byte and can store values between 0 and
255, which would have been sufficient in this scenario. The Rating column will
not be able to store the required value because only three total digits are
allowed. With this column definition, the Rating column could only hold values
between 0.00 and 9.99. DBA/Developer should not use the following CREATE TABLE
statement:
CREATE TABLE
Event (EventID int,Code char(3),
Description
varchar(30),SeatsAvail
tinyint,TypeFlag bit,
Rating decimal(3,2));
With this statement, the Rating column will not be able to store the required value because only three total digits are allowed. With this column definition, the Rating column could only hold values between 0.00 and 9.99.
No comments:
Post a Comment