I am learning PHP & MySQL from a PHP & MySQL book. And I'm on Chapter 4, and I've got a bit confused as to what this definition is used for. It says that this value is stored in the column when the row is created if no other value is given for the column. Does it mean that value is stored in the row of whatever column the row is in? Or..? Any help will be appreciated .
say you have created a table ,mytable with two columns- a1,b1. If you set 0 as defult value for column a1 , whenever you create a row if you specifically do not enter any value for a1 then a1 will have 0 as its value.
Thanks for your reply! So if it had a value of 0, 1, 2, 3, 4, 5, 6 or whatever, does it make a difference? If so, what is the difference? If you get what I mean. I'm new to this, so please bear with me. Thanks.
yes with 0,1 2 .. etc not a problem what is fact is the data type you have to keep in mind. Say if you define int as data type for a column you can nt define a value that varchar. the default value should be the kind of data that you define as data type
So if I wanted all rows on a1 to be this: So that will do that if no other value is done for every row I make?
create table mytable (a1 int, b1 varchar(20) default 'stom') then when I create any row if i dont enter any value for b1 then it will hold stom insert mytable(a1) value(10) then it will create the following row a1 b1 -- --- 10 stom then if i do the followin insert mytable(a1,b1) value(10,'kashem') then it will create the following row a1 b1 -- --- 10 kashem
Lets say you have a field "is_active" to check if the record is active or not. 0 means it is not active, 1 is active, 2 is .. etc... You would want the default value to be 0, especially if it is user entered content and then you would go about reviewing the record and changing the value to 1. Peace,
Ah, so like AUTO_INCREMENT every time they post once, so when they register, the default value is 0? I get it now! Also, about PRIMARY KEY's, for example; CREATE TABLE Member ( loginName VARCHAR(20) NOT NULL PRIMARYKEY, createDate DATE NOT NULL); PRIMARY KEY(columnname) firstly, what is a primary key and what are they used for? Secondly, the bottom of the query is PRIMARY KEY(columnname) - what do I put in the columnname bit? Sorry about this :S. Any help appreciated!