Home Database Mysql Tutorial MySQL与标准的兼容性_MySQL

MySQL与标准的兼容性_MySQL

Jun 01, 2016 pm 02:00 PM
sql database compatibility

MySQL包含了一些可能在其他SQL数据库找不到的扩充。要注意如果你使用他们,你的代码把不与其他SQL服务器兼容。在一些情况下,你可以编写包括MySQL扩展的代码,但是仍然是可移植的,通过使用/*! ... */形式的注释。在这种情况下,MySQL把进行词法分析并且执行在注释内的代码,好像它是任何其它MySQL语句,但是其他SQL服务器把忽略扩展。例如:
  
  SELECT /*! STRAIGHT_JOIN */ col_name FROM table1,table2 WHERE ...
  如果你在'!'后增加一个版本数字,该语法把仅在MySQL版本是等于或比使用的版本数字新时才执行:
  
  CREATE /*!32302 TEMPORARY */ TABLE (a int);
  
  上面的意思是如果你有3.23.02或更新,那么MySQL把使用TEMPORARY关键词。
  
  MySQL扩展被列在下面:
  字段类型MEDIUMINT、SET、ENUM和不同的BLOB和TEXT类型。
  字段属性AUTO_INCREMENT、BINARY、UNSIGNED和ZEROFILL。
  缺省地,所有的字符串比较是忽略大小写的,由当前的字符集决定了(缺省为ISO-8859-1 Latin1)排序顺序。如果你不喜欢这样,你应该用BINARY属性或使用BINARY强制符声明列,它导致根据MySQL服务器主机的ASCII顺序进行排序。
  MySQL把每个数据库映射一个MySQL数据目录下面的目录,把数据库表映射到数据库目录下的数据库文件名。这有2个含意:
  在区分大小写文件名的操作系统(象大多数 Unix 系统一样)上的MySQL中数据库名字和表名是区分大小写的。如果你有困难记得表名,接受一个一致的约定,例如总是用小写名字创建数据库和表。
  
  数据库、表、索引、列或别名可以以数字开始(但是不能仅由数字组成)。
  你可以使用标准的系统命令备份、重命名、移动、删除和拷贝表。例如,重命名一个表,重命名“.MYD”、“.MYI”和“.frm”文件为相应的表。
  在SQL语句中,你可以用db_name.tbl_name语法访问不同数据库中的表。一些SQL服务器提供同样的功能但是称它们为这User space(用户空间)。MySQL不支持类似在create table ralph.my_table...IN my_tablespace中的表空间。
  LIKE在数字列上被允许。
  
  在一SELECT语句里面使用INTO OUTFILE和STRAIGHT_JOIN。见7.12 SELECT句法.
  在一个SELECT语句中SQL_SMALL_RESULT选项。
  EXPLAIN SELECT得到怎么样联结表的描述。
  
  在一个CREATE TABLE语句里面使用索引、在字段前缀上的索引和使用INDEX或KEY。见7.7 CREATE TABLE 句法。
  CREATE TABLE使用TEMPORARY或IF NOT EXISTS。
  使用COUNT(DISTINCT list),这里“list”超过一个元素。
  在一个ALTER TABLE语句里面使用CHANGE col_name、DROP col_name或DROP INDEX。见7.8 ALTER TABLE句法。
  在一个ALTER TABLE里面语句使用IGNORE。
  
  在一个ALTER TABLE语句中使用多重ADD、ALTER、DROP或CHANGE子句。
  使用带关键词IF EXISTS的DROP TABLE。
  你能用单个DROP TABLE语句抛弃多个表。
  DELETE语句的LIMIT子句。
  INSERT和REPLACE语句的DELAYED子句。
  
  INSERT, REPLACE, DELETE和UPDATE语句的LOW_PRIORITY子句。
  使用LOAD DATA INFILE。在多数情况下,这句法与Oracle的LOAD DATA INFILE兼容。见7.16 LOAD DATA INFILE 句法。
  OPTIMIZE TABLE语句。。
  SHOW语句。见7.21 SHOW句法(得到表、列等的信息)。
  字符串可以被“"”或“'”包围,而不只是“'”。
  使用“/”转义字符。
  SET OPTION语句。见7.25 SET OPTION句法。
  你不需要命名所有在GROUP BY部分的被选择的列。这为一些很特定的情况给出更好的性能,而不是一般的查询。
  
  为了方便来自于SQL环境其他为用户,MySQL对许多函数支持别名。例如,所有的字符串功能都支持ANSI SQL句法和 ODBC句法。
  MySQL理解||和&&意味着逻辑的OR和AND,就像在C程序语言中。在MySQL中,||和OR是同义词,&&和AND是同义词。正因为这个好的句法,MySQL对字符串并置的不支持ANSI SQL ||操作符;相反使用CONCAT(),因为CONCAT()接受任何数量的参数,很容易把||操作符使用变换到MySQL。
  
  CREATE DATABASE或DROP DATABASE。见7.5 CREATE DATABASE句法。
  %操作符是MOD()一个同义词,即,N % M等价于MOD(N,M)。%支持C程序员并与PostgreSQL兼容。
  =, , =,>, >, , AND, OR或LIKE操作符可以放在SELECT语句的FROM左边用于比较列。例如:
  mysql> SELECT col1=1 AND col2=2 FROM tbl_name;
  
  LAST_INSERT_ID()函数。见20.4.29 mysql_insert_id()。
  扩展的正则表达式操作符REGEXP和NOT REGEXP。
  CONCAT()或CHAR()有一个参数或超过2个参数。(在MySQL中,这些函数可取任何数量的参数。)
  
  BIT_COUNT(), CASE, ELT(), FROM_DAYS(), FORMAT(), IF(), PASSWORD(), ENCRYPT(), md5(), ENCODE(), DECODE(), PERIOD_ADD(), PERIOD_DIFF(), TO_DAYS(),或WEEKDAY()函数。
  
  使用TRIM()整修子串。ANSI SQL 只支持单个字符的删除。
  GROUP BY函数STD(), BIT_OR()和BIT_AND()。
  使用REPLACE而不是DELETE+INSERT。见7.15 REPLACE句法。
  FLUSH flush_option语句。
  
  在一个语句用:=设置变量的可能性:
  SELECT @a:=SUM(total),@b=COUNT(*),@a/@b AS avg FROM test_table;
  SELECT @t1:=(@t2:=1)+@t3:=4,@t1,@t2,@t3;
  
   以ANSI模式运行MySQL
  如果你用--ansi选项启动mysqld,MySQL的下列行为改变。
  
  ||是字符串并置而不是OR。
  可在一个函数名字之间与“(”有任何数量的空格。这也使所有的功能名字成为保留词。
  "把是一个标识符引号字符(象MySQL `引号字符一样)而不是一个字符串引号字符。
  REAL把是FLOAT一个同义词,不是DOUBLE一个同义词。
  5.3 MySQL相比ANSI SQL92的差别
  我们尝试使得MySQL遵照ANSI SQL标准和ODBC SQL标准,但是在一些情况下,MySQL做一些不同的事情:
  
  --只是一个注释,如果后面跟一个白空字符。`--'作为一个注释的开始。
  对于VARCHAR列,当值被存储时,拖后的空格被删除。见E MySQL已知的错误和设计缺限。

  在一些情况下,CHAR列偷偷地被改变为VARCHAR列。平静的列指定变化。
  当你删除一个表时,对表的权限不自动地废除。你必须明确地发出一个REVOKE来废除对一个表的权限。见7.26 GRANT和REVOKE句法。
   MySQL缺乏的功能
  下列功能在当前的MySQL版本是没有的。对于一张优先级表指出何时新扩展可以加入MySQL, 你应该咨询在线MySQL TODO 表。这是本手册最新的TODO表版本。见F 我们想要在未来加入到MySQL的事情列表(TODO)。
  
  
  子选择
  在MySQL中下列语句还不能工作:
  
  SELECT * FROM table1 WHERE id IN (SELECT id FROM table2);
  SELECT * FROM table1 WHERE id NOT IN (SELECT id FROM table2);
  
  然而,在很多情况下,你可以重写查询,而不用子选择:
  
  SELECT table1.* FROM table1,table2 WHERE table1.id=table2.id;
  SELECT table1.* FROM table1 LEFT JOIN table2 ON table1.id=table2.id where table2.id IS NULL
  
  对于更复杂的子查询,通常你可以创建临时的表保存子查询。然而在一些情况下,这种选择把行不通。最经常遇到的情形是DELETE语句,对于它标准SQL不支持联结(join)(除了在子选择)。对于这种情况,有2个可用选择,直到子选择被MySQL支持。
  
  第一个选择是使用一种过程化的程序语言(例如Perl或PHP)来提交一个SELECT查询获得要被删除记录主键,并然后使用这些值构造DELETE语句(DELETE FROM ... WHERE ... IN (key1, key2, ...))。
  
  第二个选择是使用交互式SQL自动构造一套DELETE语句,使用MySQL扩展CONCAT()(代替标准||操作符)。例如:
  
  SELECT CONCAT('DELETE FROM tab1 WHERE pkid = ', tab1.pkid, ';')
  FROM tab1, tab2
  WHERE tab1.col1 = tab2.col2;
  
  你可以把这个查询放在一个脚本文件并且从它重定向输入到mysql命令行解释器,把其输出作为管道返回给解释器的第2个实例:
  
  prompt> mysql --skip-column-names mydb   
  MySQL仅支持INSERT ... SELECT ...和REPLACE ... SELECT ...,独立的子选择把可能在3.24.0得到,然而,在其他环境下,你现在可以使用函数IN()。
  
  
  SELECT INTO TABLE
  MySQL还不支持Oracle SQL的扩展:SELECT ... INTO TABLE ....,相反MySQL支持ANSI SQL句法INSERT INTO ... SELECT ...,基本上他们是一样的。
  
  另外,你可使用SELECT INTO OUTFILE...或CREATE TABLE ... SELECT解决你的问题。
  
  事务处理
  不支持事务处理。MySQL把在短时间内支持原子(atomic)操作,它象没有回卷的事务。用原子操作,你能执行一组INSERT/SELECT/whatever 命令并且保证没有其他线程介入。在本文中,你通常不会需要回卷。目前,你可通过使用LOCK TABLES和UNLOCK TABLES命令阻止其他线程的干扰。见7.24 LOCK TABLES/UNLOCK TABLES句法。
  
  存储过程和触发器
  一个存储过程是能在服务器中编译并存储的一套SQL命令。一旦这样做了,顾客不需要一直重新发出全部查询,而可以参考存储过程。因为查询仅需一次词法分析并且较少的信息需要在服务器和客户之间传送,因此这提供了更好的性能。你与可以通过拥有在服务器中的函数库提升概念上的层次

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

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)

Comparison and difference analysis of Bluetooth 5.3 and 5.2 versions Comparison and difference analysis of Bluetooth 5.3 and 5.2 versions Dec 28, 2023 pm 06:08 PM

Nowadays, many mobile phones claim to support Bluetooth 5.3 version, so what is the difference between Bluetooth 5.3 and 5.2? In fact, they are essentially subsequent updated versions of Bluetooth 5, and there is not much difference in most performance and functions. The difference between Bluetooth 5.3 and 5.2: 1. Data rate 1 and 5.3 can support higher data rates up to 2Mbps. 2. While 5.2 can only reach a maximum of 1Mbps, it means that 5.3 can transmit data faster and more stably. 2. Encryption control enhancement 2. Bluetooth 5.3 improves encryption key length control options, improves security, and can better connect to access control and other devices. 3. At the same time, because the administrator control is simpler, the connection can be more convenient and faster, which is not possible in 5.2.

Solution to i7-7700 unable to upgrade to Windows 11 Solution to i7-7700 unable to upgrade to Windows 11 Dec 26, 2023 pm 06:52 PM

The performance of i77700 is completely sufficient to run win11, but users find that their i77700 cannot be upgraded to win11. This is mainly due to restrictions imposed by Microsoft, so they can install it as long as they skip this restriction. i77700 cannot be upgraded to win11: 1. Because Microsoft limits the CPU version. 2. Only the eighth generation and above versions of Intel can directly upgrade to win11. 3. As the 7th generation, i77700 cannot meet the upgrade needs of win11. 4. However, i77700 is completely capable of using win11 smoothly in terms of performance. 5. So you can use the win11 direct installation system of this site. 6. After the download is complete, right-click the file and "load" it. 7. Double-click to run the "One-click

Browser compatibility Browser compatibility Sep 14, 2023 am 11:08 AM

Methods for setting browser compatibility include selecting appropriate HTML and CSS standards, using CSS prefixes and resets, using browser compatibility prefix libraries, detecting browser features, using browser compatibility tools, and conducting cross-browser testing. Detailed introduction: 1. Choose appropriate HTML and CSS standards. When writing HTML and CSS codes, you should try to follow W3C standards. Different browsers will have different support for standards, but following standards can maximize compatibility. sex; 2. Use CSS prefixes, etc.

How compatible is the Go language on Linux systems? How compatible is the Go language on Linux systems? Mar 22, 2024 am 10:36 AM

The Go language has very good compatibility on Linux systems. It can run seamlessly on various Linux distributions and supports processors of different architectures. This article will introduce the compatibility of Go language on Linux systems and demonstrate its powerful applicability through specific code examples. 1. Install the Go language environment. Installing the Go language environment on a Linux system is very simple. You only need to download the corresponding Go binary package and set the relevant environment variables. Following are the steps to install Go language on Ubuntu system:

Detailed explanation of win11 compatibility issues with win10 software Detailed explanation of win11 compatibility issues with win10 software Jan 05, 2024 am 11:18 AM

The software in the win10 system has been perfectly optimized, but for the latest win11 users, everyone must be curious about whether this system can be supported, so the following is a detailed introduction to the win11 software that does not support win10. Come and find out together. Does win11 support win10 software: 1. Win10 system software and even Win7 system applications are well compatible. 2. According to feedback from experts who use the Win11 system, there are currently no application incompatibility issues. 3. So you can upgrade boldly with confidence, but ordinary users are advised to wait until the official version of Win11 is released before upgrading. 4. Win11 not only has good compatibility, but also has Windo

Can I use Bluetooth headphones in airplane mode? Can I use Bluetooth headphones in airplane mode? Feb 19, 2024 pm 10:56 PM

With the continuous development of modern technology, wireless Bluetooth headsets have become an indispensable part of people's daily lives. The emergence of wireless headphones frees our hands, allowing us to enjoy music, calls and other entertainment activities more freely. However, when we fly, we are often asked to put our phones in airplane mode. So the question is, can I use Bluetooth headphones in airplane mode? In this article, we will explore this question. First, let’s understand what airplane mode does and means. Airplane mode is a special mode for mobile phones

WIN10 compatibility lost, steps to recover it WIN10 compatibility lost, steps to recover it Mar 27, 2024 am 11:36 AM

1. Right-click the program and find that the [Compatibility] tab is not found in the properties window that opens. 2. On the Win10 desktop, right-click the Start button in the lower left corner of the desktop and select the [Run] menu item in the pop-up menu. 3. The Win10 run window will open, enter gpedit.msc in the window, and then click the OK button. 4. The Local Group Policy Editor window will open. In the window, click the [Computer Configuration/Administrative Templates/Windows Components] menu item. 5. In the opened Windows component menu, find the [Application Compatibility] menu item, and then find the [Remove Program Compatibility Property Page] setting item in the right window. 6. Right-click the setting item, and in the pop-up menu

Best practices for resolving PHP function compatibility issues Best practices for resolving PHP function compatibility issues May 01, 2024 pm 02:42 PM

Best practices to solve PHP function compatibility issues: Use versioned function names (for example: array_map_recursive()) Leverage function aliases (for example: functionarray_map($callback,$array){...}) to check function availability (for example: if (function_exists('array_map_recursive')){...}) use namespace (for example: namespaceMyNamespace{...})

See all articles