Click to See Complete Forum and Search --> : Create Table With Default Values


Dysan
11-15-2007, 12:42 PM
Hello! I have the following code that creates a table structure. How do I give Age a default value of 0


mysql_select_db("DB", $connection);
$sql = "CREATE TABLE Person
(
Name text,
Age text,
Sex text
)";

trymbill
11-16-2007, 04:04 AM
First of, why not use varchar for name and sex and int for age? Using text for everything is not clever :)

But for your question, just add "default '0'" after "Age text" so it looks like:

mysql_select_db("DB", $connection);
$sql = "CREATE TABLE Person
(
Name text,
Age text default '0',
Sex text
)";