SQL statement problems

Source: Internet
Author: User
In the SQL statement, there is a table where the user has the id and u_id fields. if the data is inserted, the id value will automatically increase. Can the u_id obtain a random value? I am interested in learning. no one cares about it. Are you willing to help ?, No. ID. this is the auto-increment primary key. inserttablev SQL statement is incorrect.
There is a table in which the user has the id and u_id fields. if the data is inserted, the id value will automatically increase. Can the u_id also obtain a random value? I am interested in learning. no one cares about it. Are you willing to help?

------ Solution --------------------
No. ID. this is the auto-increment primary key.
------ Solution --------------------

Insert table values (null, rand ());

To obtain a random integer R in the range of I ≤ R ≤ j, use the expression FLOOR (I + RAND () * (j-I + 1 ))
------ Solution --------------------
When creating a database table:
SQL code
Create table 'user' ('id' int (6) not null AUTO_INCREMENT, 'U _ id' int (6) not null, primary key ('id ')) ENGINE = MyISAM AUTO_INCREMENT = 85 default charset = utf8 CHECKSUM = 1 DELAY_KEY_WRITE = 1 ROW_FORMAT = DYNAMIC
------ Solution --------------------
Insert values (null, rand ());

To obtain a random integer R in the range of I ≤ R ≤ j, use the expression FLOOR (I + RAND () * (j-I + 1 ))
------ Solution --------------------
Writing a stored procedure is good and flexible.
------ Solution --------------------
The auto_increment attribute increases automatically.
------ Solution --------------------
Discussion

No. ID. this is the auto-increment primary key.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.