0

i have a table named as tbl_bank, in that i have created 4 columns as id,acc_name,acc_type,bank_name.

I need id as autoincrement and acc_name as primary key. What is the solution?

Any idea?

Vinod VT
  • 6,946
  • 11
  • 51
  • 75
user3422452
  • 57
  • 1
  • 2
  • 5
  • Possible duplicate: http://stackoverflow.com/questions/1151314/i-need-to-auto-increment-a-field-in-mysql-that-is-not-primary-key – Aziz Shaikh Mar 21 '14 at 07:35
  • Possible duplicate: http://stackoverflow.com/questions/634231/can-you-use-auto-increment-in-mysql-with-out-it-being-the-primary-key – Aziz Shaikh Mar 21 '14 at 07:36
  • Is there a reason why using `unique` for `acc_name` would not work for you. Also why do you have `id` as autoincr when you don't want to use it as primary? – t.niese Mar 21 '14 at 07:37

4 Answers4

1

you should try this:

CREATE TABLE `tbl_bank` (
  `id` int(5) NOT NULL AUTO_INCREMENT,
  `acc_name` varchar(55) NOT NULL,
  `acc_type` varchar(55) NOT NULL,
  `bank_name` varchar(55) NOT NULL,
  PRIMARY KEY (`acc_name`),
  UNIQUE KEY `id` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
jmail
  • 5,944
  • 3
  • 21
  • 35
0

Try this

CREATE TABLE Persons
(
ID int NOT NULL AUTO_INCREMENT,
Acc_name varchar(255) NOT NULL PRIMARY KEY,
acc_type varchar(255),
bank_name varchar(255),
UNIQUE KEY id (id)
)

SQL FIDDLE

Nagaraj S
  • 13,316
  • 6
  • 32
  • 53
0

create table tbl_bank( id int unique auto_increment, acc_name varchar(20) not null primary key, acc_type varchar(10), bank_name varchar(20));

for further query visit kuchhbhiii.blogspot.in

y4yogi
  • 11
  • 3
-1

While creating table, use following ID int NOT NULL AUTO_INCREMENT

AK47
  • 3,707
  • 3
  • 17
  • 36