mysql中的enum和set类型_MySQL
bitsCN.com
mysql中的enum和set类型
mysql中的enum和set其实都是string类型的而且只能在指定的集合里取值,
不同的是set可以取多个值,enum只能取一个
Sql代码
CREATE TABLE `20121101_t` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(20) NOT NULL,
`cl` set('x','w','r') NOT NULL,
`c2` enum('f','d') NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB
insert into 20121101_t
values(null,'a.txt','r,w','d');
insert into 20121101_t
values(null,'b.txt','r,w','f');
比如给b.txt文件加上执行权限
Sql代码
update 20121101_t set cl = cl|1 where id =2
1是因为x权限出现在了第一个
再比如给b.txt文件去掉写权限
Sql代码
update 20121101_t set cl = cl&~2 where id =2
这时再看
Sql代码
select * from 20121101_t
1 a.txt w,r d
2 b.txt x,r f
可以仿照linux下chmod的用法,直接用数字表示权限
比如把b.txt变成只读
Sql代码
update 20121101_t set cl = 4 where id =2
比如要找到所有包含了读权限的文件
Sql代码
select * from 20121101_t where cl&4
或者
Sql代码
select * from 20121101_t where FIND_IN_SET('r',cl)>0
enum就相对简单了,比如把a.txt从文件夹变成文件
Sql代码
update 20121101_t set c2 = 'f' where id =1
bitsCN.com

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Interpretation of MyBatis dynamic SQL tags: Detailed explanation of Set tag usage MyBatis is an excellent persistence layer framework. It provides a wealth of dynamic SQL tags and can flexibly construct database operation statements. Among them, the Set tag is used to generate the SET clause in the UPDATE statement, which is very commonly used in update operations. This article will explain in detail the usage of the Set tag in MyBatis and demonstrate its functionality through specific code examples. What is Set tag Set tag is used in MyBati

Methods to delete elements: 1. Use delete() to delete the specified element from the Set object, the syntax is "setObj.delete(value);"; 2. Use clear() to delete all elements in the Set object, the syntax is "setObj.delete(value);" "setObj.clear();".

This article is based on the basics of Python and introduces how to use dict and set. The dict using the key-value storage structure is very useful in Python. It is important to choose an immutable object as the key. The most commonly used key is a string.

Preface There are two very similar methods in the commonly used collection interface List in Java: Eset(intindex,Eelement); voidadd(intindex,Eelement); both of these methods insert specified elements at specified positions in the collection, then What is the difference between these two methods? Next, let’s take a look at the differences and similarities between these two methods through ArrayList, our commonly used collection implementation. First, let’s take a look at the similarities between these two methods in ArrayList. They will insert new elements at specified positions in the collection, such as the following Example: #Insert an F in the 2nd position of the collection #Insert Listlist= through the add method

1. Overview of the Map Collection Framework The Map collection framework is a key-value pair data structure that allows you to use keys to find and store values. Each key in the Map is unique and can only be associated with one value. Common implementations in the Map collection framework include HashMap, TreeMap and LinkedHashMap. 1.HashMapHashMap is the most widely used Map implementation in Java. It stores data based on hash tables. HashMap has excellent performance, and the time complexity of search and insertion operations is O(1), but it does not guarantee the order of elements. Demo code: Mapmap=newHashMap

The set command syntax SETkeyid[FIELDnamevalue...][EXseconds][NX|XX](OBJECTgeojson)|(POINTlatlonz)|(BOUNDSminlatminlonmaxlatmaxlon)|(HASHgeohash)|(STRINGvalue) The set command is equivalent to the use of the hash command in redis. It is also a combination of key and id, but the difference is that Tile38's set command can also carry more other attributes, such as customizing the FIELD field, setting the EX validity period, etc., then we need to

1.ListList is an ordered collection in the Java collection framework that allows elements to be repeated and elements can be accessed by index. Common implementation classes of List include ArrayList, LinkedList and Vector. The following demonstrates how to use ArrayList to store a set of integers: importjava.util.ArrayList;publicclassArrayListDemo{publicstaticvoidmain(String[]args){//Create an ArrayList object ArrayListnumbers=newArr

Common uses of set include creating a Set, adding elements, deleting elements, determining whether the Set is empty, getting the size of the Set, traversing the Set, finding elements, and set operations. Detailed introduction: 1. Create a Set, Setset=newHashSet(); 2. Add elements, set.add("java"); set.add("python");; 3. Delete elements, set.remove("java"); and so on.
