In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
1. Build a table sentence:
CREATE TABLE `employees` (`emp_ no` int (11) NOT NULL, `birth_ date` date NOT NULL, `first_ name` varchar (14) NOT NULL, `last_ name` varchar (16) NOT NULL, `gender` char (1) NOT NULL, `hire_ date`date NOT NULL, PRIMARY KEY (`emp_ no`), UNIQUE KEY `idxunique_first_name_ gender` (`first_ name`, `gender`), UNIQUE KEY `uniq_idx_ firstname` (`first_ name`, `gender`) ENGINE=InnoDB DEFAULT CHARSET=utf8
2. Add unique key:
-- add unique index alter table employees add constraint idxunique_first_name_gender unique (first_name, gender)
3. Query the test statement:
-contains all fields of the index, and the order and index are the same select * from employees where first_name='Chirstian' and gender='M';-- key column values: idxunique_first_name_gender-- contains all fields of the index, but the order and index are not consistent select * from employees where gender='M' and first_name='Chirstian';-- key column values: idxunique_first_name_gender-- contains the first field of the index select * from employees where first_name='Chirstian' -- key column value: idxunique_first_name_gender-- contains the non-first field of the index select * from employees where gender='M';-- key column value: NULL
4. When querying, if there are only some or all of the columns in unique key in the where condition and the column value type is const. If you want to use unique key,where, you must have the first column when you create the unique key, and the other columns are optional.
A problem related to mysql unique key
Xxx_tab 's user_id is unique key. Let's take a look at the pseudocode:
Get user_id=10000 from xxx_tab;if exist {return ok} ret = insert user_id=10000if ret ok {return ok} return not_ok
Question: why did you end up with not_ok?
Hint: distributed impact
Summary
The above is the whole content of this article. I hope the content of this article has a certain reference and learning value for everyone's study or work. Thank you for your support. If you want to know more about it, please see the relevant links below.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.