Home > Database > Mysql Tutorial > SQL中数据库之间不兼容的语法汇总

SQL中数据库之间不兼容的语法汇总

WBOY
Release: 2016-06-07 15:30:26
Original
1396 people have browsed it

1.TOP SQL Server 的语法: SELECT TOP number columnName FROM tableName MySQL 的语法: SELECT columnName FROM tableName LIMIT number Oracle 的语法: SELECT columnName FROM tableName WHERE ROWNUM=number 2.创建表时添加UNIQUE/PRIMARY KEY/FOREIG

1.TOP

SQL Server的语法:

SELECT TOP number columnName

FROM tableName

MySQL的语法:

SELECT columnName

FROM tableName

LIMIT number

Oracle的语法:

SELECT columnName

FROM tableName

WHERE ROWNUM

2.创建表时添加UNIQUE/PRIMARY KEY/FOREIGN KEY/CHECK(不需名为约束人为命时才有不兼容)

   (接下来举例说明)

SQL Server/Oracle/Access的语法:

CREATE TABLE Students

(Name char(10) NOT NULL,

Id char(10) NOT NULL UNIQUE

)

MySQL的语法:

CREATE TABLE Students

(Name char(10) NOT NULL,

Id char(10) NOT NULL,

UNIQUE(Id)

)

PRIMARY KEY和UNIQUE同理,只是把UNIQUE换成PRIMARY KEY而已;

FOREIGN KEY也是同理,只不过要加上REFERENCES的内容而已;

CHECK也是同理,只不过要加上约束的内容而已;

3.撤销UNIQUE

SQL Server/Oracle/Access的语法:

ALTER TABLE TableName

DROP CONSTRAINT constraintName

MySQL的语法:

ALTER TABLE TableName

DROP INDEX indexName

4.撤销PRIMARY KEY

SQL Server/Oracle/Access的语法:

ALTER TABLE TableName

DROP CONSTRAINT constraintName

MySQL的语法:

ALTER TABLE TableName

DROP PRIMARY KEY

5.撤销FOREIGN KEY

SQL Server/Oracle/Access的语法:

ALTER TABLE TableName

DROP CONSTRAINT constraintName

MySQL的语法:

ALTER TABLE TableName

DROP FOREIGN KEY foreignKeyName

6.撤销CHECK

SQL Server/Oracle/Access的语法:

ALTER TABLE TableName

DROP CONSTRAINT constraintName

MySQL的语法:

ALTER TABLE TableName

DROP CHECK checkName

7.为已有的表添加DEFAULT

SQL Server/Oracle/Access的语法:

ALTER TABLE tableName

ALTER columnName SET DEFAULT 'defaultValue'

MySQL的语法:

ALTER TABLE tableName

ALTER COLUMN columnName SET DEFAULT 'defaultValue'

8.撤销DEFAULT

SQL Server/Oracle/Access的语法:

ALTER TABLE tableName

ALTER columnName DROP DEFAULT 

MySQL的语法:

ALTER TABLE tableName

ALTER COLUMN columnName DROP DEFAULT

9.撤销引索

SQL Server的语法:

DROP INDEX tableName.columnName

Oracle的语法:

DROP INDEX indexName

Access的语法:

DROP INDEX indexName ON tableName

MySQL的语法:

ALTER TABLE tableName

DROP INDEX indexName


当然,不同的数据库在时间处理等方面还有不同,但由于文本过长,在此不再赘述。





source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template