ago • retagged ago by
44 views
0 0 votes

Consider:

CREATE TABLE products (
    id INTEGER PRIMARY KEY,
    stock INTEGER NOT NULL,
    price INTEGER NOT NULL,
    name VARCHAR(10) NOT NULL,
    category CHAR(6) NOT NULL,
    serial_number CHAR(20)
);

Assume:

  • an $\mathrm{INTEGER}$ occupies $4$ bytes,
     
  • $\mathrm{CHAR(n)}$ occupies exactly $n$ bytes,
     
  • $\mathrm{VARCHAR(n)}$ occupies at most $n$ bytes,
     
  • the record header occupies $8$ bytes,
     
  • $\mathrm{serial\_number}$ may be $\mathrm{NULL}$.

Which of the following can be the size, in bytes, of some record using a variable-length representation?

  1. $18$
     
  2. $27$
     
  3. $48$
     
  4. $55$

1 Answer

0 0 votes


First, calculate the fixed part:

$\mathrm{Header}=8$

$\mathrm{id}=4$

$\mathrm{stock}=4$

$\mathrm{price}=4$

$\mathrm{category}=6$

Therefore:

$8+4+4+4+6=26$

$\mathrm{name}$ is $\mathrm{VARCHAR}(10)$, so it can contribute from $0$ through $10$ bytes.


Case $\mathbf{1}: \mathrm{serial\_number}$ is NULL

Possible record sizes are:

$26\mathrm{\ through\ }36$

Among the options $27$ is possible.

So B is correct.
 

Case $\mathbf{2}: \mathrm{serial\_number}$ is not NULL

$\mathrm{CHAR}(20)$ adds exactly $20$ bytes:

$46\mathrm{\ through\ }56$

Therefore, both $48,\ 55$ are possible.

So C and D are also correct.

ago
Answer:
Position:
Show:

Related questions

0 0 votes
1 1 answer
47
47 views
GO Classes asked 3 days ago
47 views
Which of the following are benefits of using a record header for variable-length records?Delimiter characters between fields are not required. It always uses equal or les...
0 0 votes
1 1 answer
46
46 views
GO Classes asked 3 days ago
46 views
Consider,Universities( name TEXT, abbrev CHAR(3), addr TEXT, zip CHAR(5), phone TEXT, enrolled INTEGER )Assume,record header = $4$ bytes, integer = $4$ bytes, a $\mathrm{...
2 2 votes
1 1 answer
108
108 views
GO Classes asked 3 days ago
108 views
Consider,CREATE TABLE zoomers ( lecture_id INTEGER PRIMARY KEY, week INTEGER NOT NULL, topic VARCHAR(30) NOT NULL, num_thanks INTEGER, poppin_chat BOOLEAN );Assume,intege...
1 1 vote
1 1 answer
46
46 views
GO Classes asked 3 days ago
46 views
Consider the following statement:In fixed-length records, a character field of type $\mathrm{CHAR}$ is not allowed.Enter $1$ if the statement is true and $0$ if it is fal...