how to create table in mysql with primary key and autoincrement ?

96

Create table in mysql with primary key and autoincrement:

Use Query for create table:

CREATE TABLE `careers_course_exam` (
`id` int(15) NOT NULL AUTO_INCREMENT,
`course_id` int(11) NOT NULL,
`exam_nid` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1

 

OUTPUT LIKE:


mysql> CREATE TABLE `careers_zone` (
-> `id` int(15) NOT NULL AUTO_INCREMENT,
-> `course_id` int(11) NOT NULL,
-> `exam_nid` int(11) NOT NULL,
-> PRIMARY KEY (`id`)
-> ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
Query OK, 0 rows affected (0.02 sec)

mysql> desc careers_zone;
+-----------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+---------+------+-----+---------+----------------+
| id | int(15) | NO | PRI | NULL | auto_increment |
| course_id | int(11) | NO | | NULL | |
| exam_nid | int(11) | NO | | NULL | |
+-----------+---------+------+-----+---------+----------------+
3 rows in set (0.00 sec)

 

LEAVE A REPLY

Please enter your comment!
Please enter your name here