How to Drop the Default Value of a Column of a MySQL Table Using PHP



PHP







In this article, we show how to drop the default value of a column of a MySQL table using PHP.

So we've shown how to set the default value of a column of a MySQL Using PHP.

Now we will show how to drop the default value of a column.

So whatever the default value of a column was set to, whether a NULL value or a certain character or string, we can get rid of it.

With SQL query languages, like MySQL, a user has the option have dropping the default value of a column.

The general format of the MySQL query to drop the default value of a column of a MySQL table is shown below.





So the above is the MySQL code to drop the default value for the state column in the customers table.

So whatever the default value of the column was, it is now dropped and gone.

So all rows in the state column will now not have a default value.

We'll now show how to tie this in with PHP.



So, first, we must connect to the database.

After we do this, we create a variable named $dropdefault. This $dropdefault variable is set equal to a mysql_query() function that has the parameter "ALTER TABLE customers ALTER state DROP DEFAULT". This drops the default value of the state column.

So this is how you can drop the default value of all of the rows of a column of a MySQL table using PHP.


Related Resources

How to Set the Default Value of a Column of a MySQL Table Using PHP

How to Add a Column to a MySQL Table Using PHP

How to Add a Primary Key to a Column of a MySQL Table Using PHP

How to Make a Column of a MySQL Table Unique Using PHP

How to Rename a Column of a MySQL Table Using PHP

How to Delete a Column of a MySQL Table Using PHP

How to Modify the Defintion or Data Type of a Column of a MySQL Table Using PHP

How to Insert Data into a MySQL Table Using PHP

How to Delete a Row of a MySQL Table Using PHP

How to Delete All Rows of a MySQL Table Using PHP

How to Update a Value in a MySQL Table Using PHP

How to Copy a Table Definition in MySQL Using PHP

HTML Comment Box is loading comments...