raman Posted November 13, 2008 Share Posted November 13, 2008 I have defined a field in my database table which has only two values -Yes or No, since the entries with Yes are few in number in the table I had entered only those and the rest I wanted that the table shoud take as 'No' by default. So I have tried the following options for it for datatype ut in none of the cases the default value shows up. alter table cryptovir change vacinfo vacinfo enum('No','Yes') NOT NULL; alter table cryptovir change vacinfo vacinfo varchar(3) default 'No' NOT NULL; Then I do select * from cryptovir where vacinfo='No'; But it says empty set Link to comment https://forums.phpfreaks.com/topic/132523-default-value-not-showing-up/ Share on other sites More sharing options...
Mchl Posted November 13, 2008 Share Posted November 13, 2008 You must update those entries, that have NULL value UPDATE cryptovir SET vacinfo = 'No' WHERE vacinfo IS NULL; As a side note: for Yes/No columns you should ideally use TINYINT type, and store 'Yes' as 1 and 'No' as 0 Link to comment https://forums.phpfreaks.com/topic/132523-default-value-not-showing-up/#findComment-689124 Share on other sites More sharing options...
raman Posted November 13, 2008 Author Share Posted November 13, 2008 When I give this updata command it says 0 rows affected. Link to comment https://forums.phpfreaks.com/topic/132523-default-value-not-showing-up/#findComment-689132 Share on other sites More sharing options...
raman Posted November 13, 2008 Author Share Posted November 13, 2008 As far as I know tinyint data type is to store small numbers. To use 0 and 1 I have to substitute 1 in place of 'Yes'. Link to comment https://forums.phpfreaks.com/topic/132523-default-value-not-showing-up/#findComment-689133 Share on other sites More sharing options...
Mchl Posted November 13, 2008 Share Posted November 13, 2008 As far as I know tinyint data type is to store small numbers. To use 0 and 1 I have to substitute 1 in place of 'Yes'. tinyint is also comonly used to store boolean values, and a yes/no column is exactly that. Of course you can also use ENUM as in one of your examples. Just don't use varchar. As for why UPDATE query affected 0 rows... I have no clue now... Could you paste a row from your table, where you would like to set 'vacinfo' to 'No' ? Doesn't have to be whole row. Link to comment https://forums.phpfreaks.com/topic/132523-default-value-not-showing-up/#findComment-689135 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.