在MySQL数据库中选择php-session-id作为主键是一个好主意吗?

Is it a good idea to choose php-session-id as primary key in a MySQL-Database? Will there be unexpected surprises?

Why I am asking this question: I want to store visitor-behavior and want to identify visitors on their session-id at that time.

I do not know exactly what criteria a PHP session ID is generated. That's why I also do not know if someday might exist duplicates.

EDIT2: Aside from performance issues a session ID is not always unique. Therefore, one should not use it as a PK. See here Link1

This is not a good idea because, primary keys are advised to be integers which helps for indexing. If session ID is unique of course you can use it as a database primary key but i hope you consider not to for the sake of your database design and speed.

Why I am asking this question: I want to store visitor-behavior and want to identify visitors on their session-id at that time.

Why don't you add non primary key column called session-id ? You can still identify them that way.

About uniqueness, please refer to this link

Why I am asking this question: I want to store visitor-behavior and want to identify visitors on their session-id at that time.

Just use cookie. Store a token in cookie, and store that token along with visitor_id (an auto increment integer and primary key) and other other behavioral data you want in MySQL. Storing session files that long to remember a visitor will be a burden over your storage.

And putting php session id as primary is not an option that anyone will choose for their database. By the way session id changes with every restart of browser, considering you haven't gone wild to change session.cookie-lifetime and session.gc-maxlifetime(Source), then how do you recognize the already visited visitor, who has now a new session id.

I don't know about weather to choose php-session-id as primary key in a MySQL-Database is a good idea or not but it's not a bad idea though because if there was ever a breach of security in our script the hacker couldn't drop tables from our database. If you're really paranoid, create a different user for each function.

Check Link Below For better Understanding http://www.wikihow.com/Create-a-Secure-Session-Managment-System-in-PHP-and-MySQL