如何在mysql中将varchar作为主键

问题描述:

我有表ordertable {customer_id,oid,order_quantity,Order_amount,date}



在此表中我想生成oid为(o1,o2,o3,o4 ...............等)并将其作为主键。可以在mysql中使用







请帮帮我。

















谢谢

I have table ordertable{customer_id,oid,order_quantity,Order_amount,date}

in this table i want generate oid as(o1,o2,o3,o4..............etc) and make this as primary key.Is it possible in mysql



Please help me.








Thanks

你好,



你不能直接这样做。但是这篇文章 [ ^ ]可以帮助您实现这一目标。



问候,
Hello,

You can not directly do so. However this article[^] should help you in achieving this.

Regards,


我不鼓励你使用nvarchar列作为主键。

为什么?因为索引nvarchar比整数类型更昂贵。

更好的是有一个整数类型的自动生成主键;这并不妨碍使用nvarchar列来存储生成的订单ID。通过这样做,当您查询订单表时,您将获得更好的表现。
I don't encourage you to use nvarchar column as a primary key.
Why ? Because indexing an nvarchar is much more costly than an integer type.
Better have an autogenerated primary key of integer type ; this does not prevent the use of a nvarchar column to store a generated order id. By doing this you will have much better performances when you will query your orders table.