Advertisements
Advertisements
प्रश्न
Differentiate between CHAR and VARCHAR data types in SQL with appropriate examples.
उत्तर
S. No. | CHAR | VARCHAR |
1. | Used to store strings of fixed size. | Used to store strings of variable length. |
2. | Uses a fixed amount of storage, based on the size of the column. | Use varying amounts of storage space based on the size of the string stored. |
3. | Takes up 1 to 4 bytes for each character, based on the collation setting. | Takes up 1 to 4 bytes for each character based on the collation and requires one or more bytes to store the length of the data. |
4. | Better performance. | Slightly poorer performance because length has to be accounted for. |
Example: Consider the table student given below:
Table: Student | ||||
Roll | Name | Phone | Aadhar | Marks |
Every value in the Name field will take up 30 characters if the user selects char(30), regardless of whether "Ria" or "Ramakrishnan Ayyar" is the saved name.
If varchar(30) is used, "Ria" will occupy 3 units, whereas "Ramakrishnan Ayyar" will take 18 units.
APPEARS IN
संबंधित प्रश्न
Which of the following is not a valid SQL type?
MySQL is not:
In database, a column is known as:
What does data type indicate?
______ decides the operations that can be performed on an attribute.
Which datatype specifies character type data of length where n could be any value from 0 to 65535?
Date datatype is stored as:
Restrictions on the type of values that an attribute can have are referred to as:
Using the sports database containing two relations (TEAM, MATCH_DETAILS) and write the Query for the following:
Change the name of the relation TEAM to T_DATA. Also, change the attributes TeamID and TeamName to T_ID and T_NAME respectively.
In a table in the MYSQL database, an attribute A of datatype varchar(20) has the value “Keshav”. The attribute B of datatype char(20) has the value “Meenakshi”. How many characters are occupied by attribute A and attribute B?
Kabir wants to write a program in Python to insert the following record in the table named Student in MYSQL database,
SCHOOL:
- rno(Roll number) - integer
- name(Name) - string
- DOB (Date of birth) - Date
- Fee - float
Note the following to establish connectivity between Python and MySQL:
- Username - root
- Password - tiger
- Host - localhost
The values of fields rno, name, DOB and fee has to be accepted from the user. Help Kabir to write the program in Python.
Zack is working in a database named SPORT, in which he has created a table named “Sports” containing columns SportId, SportName, no_of_players, and category.
After creating the table, he realized that the attribute, category has to be deleted from the table and a new attribute TypeSport of data type string has to be added. This attribute TypeSport cannot be left blank. Help Zack write the commands to complete both the tasks.
Sartaj has created a table named Student in MYSQL database, SCHOOL:
- rno(Roll number )- integer
- name(Name) - string
- DOB (Date of birth) – Date
- Fee – float
Note the following to establish connectivity between Python and MySQL:
- Username - root
- Password - tiger
- Host - localhost
Sartaj, now wants to display the records of students whose fee is more than 5000. Help Sartaj to write the program in Python.