Mysql Alter Allow Null

Mysql Alter Allow Null is used to change the Null Type of a column in a table.The Allow Null allows the null type characteristics in a column of the table.

Mysql Alter Allow Null

Mysql Alter Allow Null

     

Mysql Alter Allow Null is used to change the Null Type of a column in a table.The Allow Null allows the null type characteristics in a column of the table. The Null Type column can be leave empty.

Understand with Example

The section of Tutorial illustrate an example from 'Mysql Alter Allow Null'.To understand this example we create a table 'usertable' with required fieldname and datatype respectively.

 

 

 

Create table 'usertable':

CREATE TABLE `usertable` ( 
`username` varchar(200) NOT NULL, 
`first_name` varchar(200) NOT NULL, 
`last_name` varchar(200) NOT NULL 
)

Query to insert records or rows to the table 'usertable':

The insert into is used to add the records or rows to the table 'usertable'.


insert into usertable values('vin','Vineet','Bansal');
insert into usertable values(' srbh','Sourabh','Ranjan');
insert into usertable values(' amit','Amit','Kumar');

insert into usertable values('sandeep','Sandeep','Kumar');

Query to view the details of 'usertable':

The Select Query helps you to return the detail from table 'usertable'.

select * from usertable;

 

+----------+------------+-----------+
| username | first_name | last_name |
+----------+------------+-----------+
| vin | Vineet | Bansal |
| srbh | Sourabh | Ranjan |
| amit | Amit | Kumar |
| sandeep | Sandeep | Kumar |

Alter Table "usertable" last_name allow NULL

The Alter Query is used to modify or change the 'usertable ' definition and modify keyword allows the null value to be 'YES' in the table 'usertable'.

ALTER table usertable Modify last_name varchar(50) null;

Describe Table:

The Describe Table is used to describe the FieldType,Null,Key,etc of table 'usertable'..

Describe usertable;

 

+------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+-------+
| username | varchar(50) | NO | | | |
| first_name | varchar(200) | NO | | | |
| last_name | varchar(50) | YES | | | |
+------------+--------------+------+-----+---------+-------+