Which MySQL Datatype should be used for storing BloodType?

MySQLMySQLi Database

To store BloodType, use varchar(3) or ENUM. Let us first create a table −

mysql> create table DemoTable1855
     (
     BloodType varchar(3)
     );
Query OK, 0 rows affected (0.00 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable1855 values('A+');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1855 values('A-');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1855 values('B+');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1855 values('B-');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1855 values('AB+');
Query OK, 1 row affected (0.00 sec)

Display all records from the table using select statement −

mysql> select * from DemoTable1855;

This will produce the following output −

+-----------+
| BloodType |
+-----------+
| A+        |
| A-        |
| B+        |
| B-        |
| AB+       |
+-----------+
5 rows in set (0.00 sec)
raja
Published on 26-Dec-2019 11:05:52
Advertisements