Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
How To Get the ID Column Auto-Incremented
How To Get the ID Column Auto-Incremented? - MySQL FAQs - Managing Tables and Running Queries with PHP Scripts
✍: FYIcenter.com
Many tables require an ID column to assign a unique ID number for each row in the table. For example, if you have a table to hold forum member profiles, you need an ID number to identify each member. To allow MySQL server to automatically assign a new ID number for each new record, you can define the ID column with AUTO_INCREMENT and PRIMARY KEY attributes as shown in the following sample script:
<?php include "mysql_connection.php"; $sql = "CREATE TABLE fyi_users (" . " id INTEGER NOT NULL AUTO_INCREMENT" . ", name VARCHAR(80) NOT NULL" . ", email VARCHAR(80)" . ", time TIMESTAMP DEFAULT CURRENT_TIMESTAMP()" . ", PRIMARY KEY (id)" . ")"; if (mysql_query($sql, $con)) { print("Table fyi_users created.\n"); } else { print("Table creation failed.\n"); } mysql_close($con); ?>
If you run this script, a new table will be created with ID column defined as auto-increment. The sample script below inserts two records with ID values assigned by MySQL server:
If you run this script, you will get something like this:
1 rows inserted. 1 rows inserted. 1, John King, 2006-07-01 23:02:39 2, Nancy Greenberg, 2006-07-01 23:02:39
2007-05-11, 5632👍, 0💬
Popular Posts:
How can I search for data in a linked list? Unfortunately, the only way to search a linked list is w...
How To Return the Second 5 Rows? - MySQL FAQs - SQL SELECT Statements with JOIN and Subqueries If yo...
What is the difference between delegate and events? ã Actually events use delegates in bottom. But ...
How To Assign Debug Privileges to a User? - Oracle DBA FAQ - Introduction to Oracle SQL Developer In...
.NET INTERVIEW QUESTIONS - How can you avoid deadlock in threading? A good and careful planning can ...