문제

I am coding a messaging system and I don't want to have short IDs shown, is there any way that MySQL can generate a UID which is unique as UID suggests?

I need to know how I can do this with ONLY MySQL, no PHP, JavaScript or anything else, just MySQL, if not possible, fine, I just want to make sure.

Sorry, I should have made it more clear when I say UID I just mean "Unique ID" but I need it in a multidigit number only, e.g. 914888629, 3890692140

도움이 되었습니까?

해결책

If you don't want globally unique IDs, just a unique ID (a different number each time you call it), then you can create a table with only an integer auto_increment non-null column and issue the following two queries:

INSERT INTO tbl1 SET col1 = NULL;
SELECT LAST_INSERT_ID();

To start the number at something other than 1, for example, to start at 10 digits, set it like this:

ALTER TABLE tbl1 AUTO_INCREMENT = 1000000000

다른 팁

MySQL has a function for that. Try:

SELECT UUID();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top