Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Assignment:- 04

Data types

Instructions:
Please share your answers filled in line in the Word document. Submit code
separately wherever applicable.

Please ensure you update all the details:


Name: ____Ritika awasthi_________ Batch ID: ___________
Topic: Introduction to Database

1. Create a database with a sales table containing data types like int,
varchar, char ,date, time, timestamp, Boolean, decimal, text ?
2. Insert 10 random values in the table ?
3. Change the data type of the existing column from DECIMAL (10,2) to
FLOAT ?
4. Change the data type of the existing column from Text to Varchar?
5. What is “BLOB” Data Type in SQL, what are different types of BLOB?
6. Write different character data types and different numerical data types?

1. CREATE DATABASE sales_database;


USE sales_database;

CREATE TABLE sales (


id INT AUTO_INCREMENT PRIMARY KEY,
product_name VARCHAR(100),
category CHAR(10),
sale_date DATE,
sale_time TIME,
sale_timestamp TIMESTAMP,
is_returned BOOLEAN,

© 360DigiTMG. All Rights Reserved.


Assignment:- 04
Data types
price DECIMAL(10, 2),
customer_feedback TEXT
);

2.INSERT INTO sales (product_name, category, sale_date, sale_time, sale_timestamp,


is_returned, price, customer_feedback)
VALUES
('Product A', 'Cat1', '2024-02-01', '12:30:00', NOW(), 0, 99.99, 'Good'),
('Product B', 'Cat2', '2024-02-02', '10:45:00', NOW(), 1, 49.99, 'Not satisfied'),
('Product C', 'Cat3', '2024-02-03', '15:20:00', NOW(), 0, 199.99, 'Excellent'),
('Product D', 'Cat1', '2024-02-04', '09:10:00', NOW(), 0, 149.99, 'Average'),
('Product E', 'Cat2', '2024-02-05', '17:55:00', NOW(), 1, 79.99, 'Very good'),
('Product F', 'Cat3', '2024-02-06', '11:40:00', NOW(), 0, 129.99, 'Satisfactory'),
('Product G', 'Cat1', '2024-02-07', '14:25:00', NOW(), 1, 169.99, 'Poor'),
('Product H', 'Cat2', '2024-02-08', '08:15:00', NOW(), 0, 89.99, 'Average'),
('Product I', 'Cat3', '2024-02-09', '16:50:00', NOW(), 0, 109.99, 'Good'),
('Product J', 'Cat1', '2024-02-10', '13:05:00', NOW(), 1, 199.99, 'Excellent');

3.ALTER TABLE sales


MODIFY COLUMN price FLOAT;

4.ALTER TABLE sales


MODIFY COLUMN customer_feedback VARCHAR(255);

5.In SQL, BLOB stands for Binary Large Object, and it is a data type used to store binary
data, such as images, audio files, video files, and other types of large binary objects.
BLOB data types are particularly useful when you need to store and retrieve binary data
in a database.

© 360DigiTMG. All Rights Reserved.


Assignment:- 04
Data types
There are different types of BLOBs, each designed to handle different types of binary
data:

BLOB (Binary Large Object):

The generic BLOB type can store any binary data, including images, audio, video, and
other large objects.
It is typically used when you need to store binary data without any specific format or
structure.
TINYBLOB:

TINYBLOB is a variation of BLOB that can store up to 255 bytes of binary data.
It is suitable for storing small binary objects such as icons or small images.
MEDIUMBLOB:

MEDIUMBLOB is another variation of BLOB that can store up to 16 megabytes (16MB)


of binary data.
It is suitable for storing medium-sized binary objects such as photos or audio clips.
LONGBLOB:

LONGBLOB is the largest variation of BLOB and can store up to 4 gigabytes (4GB) of
binary data.
It is suitable for storing large binary objects such as high-resolution images, videos, or
large documents.

6.Character Data Types:

CHAR(n): Fixed-length character string with a maximum length of n characters.


Padding with spaces if the length of the string is less than n.
VARCHAR(n): Variable-length character string with a maximum length of n characters.
Only the actual length of the string is stored, no padding.

© 360DigiTMG. All Rights Reserved.


Assignment:- 04
Data types
TEXT: Variable-length character string with no maximum length.
Suitable for storing large amounts of text data.

Numerical Data Types:

INT: Integer data type that stores whole numbers.


Typically 4 bytes in size and can store values ranging from -2,147,483,648 to
2,147,483,647.

BigINT: Integer data type with larger storage capacity than INT.
Typically 8 bytes in size and can store values ranging from -9,223,372,036,854,775,808
to 9,223,372,036,854,775,807.
DECIMAL(p, s) or NUMERIC(p, s):

Fixed-point numeric data type that stores exact numeric values with specified precision p
and scale s.
Precision (p) represents the total number of digits, and scale (s) represents the number
of digits to the right of the decimal point.

FLOAT or DOUBLE:Floating-point numeric data type that stores approximate numeric


values.
Typically used for scientific calculations or when precision is not critical.

© 360DigiTMG. All Rights Reserved.

You might also like