0% found this document useful (0 votes)
13 views4 pages

IT4 It

Uploaded by

39694
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views4 pages

IT4 It

Uploaded by

39694
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Additional Notes

Short Answer Questions


1. What are the different categories of data types in MySQL?

📌
Ans:

📌
Text

📌
Number
Date

2. What is the difference between CHAR and VARCHAR?


Ans: CHAR stores a fixed-length string (up to 255 characters), while VARCHAR stores a
variable-length string (also up to 255 characters by default).

3. Describe the BLOB data type.


Ans: BLOBs (Binary Large Objects) store binary data like images or audio files.

4. What is the range of values that a TINYINT data type can hold?
Ans: TINYINT can hold values from -128 to 127 normally, and from 0 to 255 if specified
as UNSIGNED.

5. What is the difference between INT and BIGINT?


Ans: INT stores integers typically within the range -2147483648 to 2147483647, while
BIGINT can store larger integers.

6. What date formats are supported by the DATE data type?


Ans: DATE stores dates in the format YYYY-MM-DD.
7. Explain the NOT NULL constraint in MySQL.
Ans: The NOT NULL constraint ensures that a column cannot contain any NULL
value. It enforces that a value must be provided for the column.

8. What is the purpose of a UNIQUE constraint?


Ans: UNIQUE ensures no duplicate values exist in a specific column (except for one
possible NULL value).

9. Provide the syntax for adding a FOREIGN KEY to a table.


Ans: FOREIGN KEY (column_name) REFERENCES
primary_table_name(column_name);

10. Write an SQL statement to remove all rows from the Employee table
while keeping the table structure intact.
Ans: TRUNCATE TABLE Employee;

11. What is the purpose of defining a data type for a column in a database
table?
Ans: The data type defines the operations that can be done directly on the data. For
example, if a column is defined as an integer, you can perform arithmetic operations
like summing the data.

Long Answer Questions


1. Provide an example of how to create a table with a ‘PRIMARY KEY’.
Ans:
CREATE TABLE person (
person_id INT AUTO_INCREMENT,
name VARCHAR(100),
age INT,
PRIMARY KEY (person_id)
);

2. Explain the difference between CHAR and VARCHAR data types in


MySQL, including their use cases and limitations.
Ans: CHAR and VARCHAR are both used to store string data in MySQL, but they have
key differences. CHAR is used to store fixed-length strings. If you define a column as
CHAR(10), it will always take up 10 bytes of storage, even if the string is shorter. This
can be useful for storing data where the length is uniform, such as fixed-length codes.
On the other hand, VARCHAR is used to store variable-length strings. If you define a
column as VARCHAR(10), it will only use as much storage as necessary for the string,
plus one byte for the length (two bytes if the maximum length is more than 255). This
makes VARCHAR more space-efficient for storing strings of varying lengths.

3. Define a primary key and a foreign key in the context of a relational


database. How do they differ in terms of their purpose and usage?
Ans: A primary key is a column or a set of columns in a relational database table that
uniquely identifies each row in that table. Its main purpose is to ensure that each
record can be uniquely identified and accessed. A primary key cannot contain NULL
values and must contain unique values.
A foreign key, on the other hand, is a column or a set of columns in a table that is used
to establish a link between the data in two tables. It refers to the primary key of
another table, ensuring referential integrity by enforcing that the value in the foreign
key column(s) must match a value in the referenced primary key column(s).
The key difference is that a primary key uniquely identifies records within its own
table, whereas a foreign key establishes a relationship between records in different
tables.
3. You are designing a database schema for a hospital management system.
Explain how you would utilize different data types for storing patient
information efficiently.
Ans: Patients Table:
CREATE TABLE patients (
patient_id INT AUTO_INCREMENT PRIMARY KEY,
patient_name VARCHAR(100),
date_of_birth DATE,
gender ENUM('Male', 'Female', 'Other'),
address TEXT,
medical_history TEXT,
contact_number VARCHAR(20)
);

4. Write an SQL commands for


Create a database named LIBRARY
Ans:CREATE DATABASE LIBRARY;

5.Create a table BOOK with the following fields

BookId int Primary Key


BookName varchar(20)

ANS:CREATE TABLE BOOK (


BookId INT PRIMARY KEY,
BookName VARCHAR(20)
);

You might also like