Specifying Default Values 1 : Default Value « Table Index « SQL / MySQL

SQL / MySQL
1. Backup Load
2. Command MySQL
3. Cursor
4. Data Type
5. Database
6. Date Time
7. Flow Control
8. Function
9. Insert Delete Update
10. Join
11. Key
12. Math
13. Procedure Function
14. Select Clause
15. String
16. Table Index
17. Transaction
18. Trigger
19. User Permission
20. View
21. Where Clause
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
SQL / MySQL » Table Index » Default Value 
Specifying Default Values 1

/*
mysql> DROP TABLE Employee;
Query OK, 0 rows affected (0.01 sec)

mysql> CREATE TABLE Employee (
    ->    Name    VARCHAR(50) NOT NULL,
    ->    Phone VARCHAR(15) DEFAULT 'Unknown Phone' NOT NULL);
Query OK, 0 rows affected (0.06 sec)

mysql> Describe Employee;
+-------+-------------+------+-----+---------------+-------+
| Field | Type        | Null | Key | Default       | Extra |
+-------+-------------+------+-----+---------------+-------+
| Name  | varchar(50) |      |     |               |       |
| Phone | varchar(15) |      |     | Unknown Phone |       |
+-------+-------------+------+-----+---------------+-------+
2 rows in set (0.00 sec)

mysql> INSERT INTO Employee (Name, Phone) VALUES ('Joe Yin', '666 2323');
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO Employee (Name) VALUES ('Joe Yin');
Query OK, 1 row affected (0.01 sec)

mysql> INSERT INTO Employee (Name, Phone) VALUES ('Joe Yin', NULL);
ERROR 1048 (23000): Column 'Phone' cannot be null
mysql> select * from Friday;
ERROR 1146 (42S02): Table 't.friday' doesn't exist

*/  
DROP TABLE Employee;

CREATE TABLE Employee (
   Name    VARCHAR(50NOT NULL, 
   Phone VARCHAR(15DEFAULT 'Unknown Phone' NOT NULL);

Describe Employee;

INSERT INTO Employee (Name, PhoneVALUES ('Joe Yin', '666 2323');
INSERT INTO Employee (NameVALUES ('Joe Yin');
INSERT INTO Employee (Name, PhoneVALUES ('Joe Yin', NULL);

select from Friday;
           
       
Related examples in the same category
ww___w__._ja__v_a2s___._c_om___ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.