Home Database Mysql Tutorial mysql中的enum和set类型_MySQL

mysql中的enum和set类型_MySQL

Jun 01, 2016 pm 01:38 PM
set

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
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Detailed explanation of the Set tag function in MyBatis dynamic SQL tags Detailed explanation of the Set tag function in MyBatis dynamic SQL tags Feb 26, 2024 pm 07:48 PM

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

How to delete elements from set in javascript How to delete elements from set in javascript Jan 12, 2022 am 10:56 AM

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();".

Inventory of common uses of dict and set in Python programming Inventory of common uses of dict and set in Python programming Jul 25, 2023 pm 04:52 PM

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.

What is the difference between the set method and the add method in List in java? What is the difference between the set method and the add method in List in java? Apr 19, 2023 pm 07:49 PM

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

Comparison of Java Map and other collection frameworks: advantages and disadvantages analysis and application scenario guide Comparison of Java Map and other collection frameworks: advantages and disadvantages analysis and application scenario guide Feb 19, 2024 pm 10:24 PM

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

How to implement the Set command of Springboot integrated Tile client How to implement the Set command of Springboot integrated Tile client May 19, 2023 pm 01:37 PM

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

Java Collection Framework Practical Guide: Teach you step by step how to use the framework and solve practical problems Java Collection Framework Practical Guide: Teach you step by step how to use the framework and solve practical problems Feb 23, 2024 am 10:52 AM

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 Common uses of set Oct 24, 2023 am 11:25 AM

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.

See all articles