时间:2021-07-01 10:21:17 帮助过:67人阅读
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<=number
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 KEYSQL Server/Oracle/Access的语法:
ALTER TABLE TableName
DROP CONSTRAINT constraintName
MySQL的语法:
ALTER TABLE TableName
DROP FOREIGN KEY foreignKeyName
SQL Server/Oracle/Access的语法:
ALTER TABLE TableName
DROP CONSTRAINT constraintName
MySQL的语法:
ALTER TABLE TableName
DROP CHECK checkName7.为已有的表添加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
SQL Server的语法:
DROP INDEX tableName.columnName
Oracle的语法:
DROP INDEX indexName
Access的语法:
DROP INDEX indexName ON tableName
MySQL的语法:
ALTER TABLE tableName
DROP INDEX indexName
当然,不同的数据库在时间处理等方面还有不同,但由于文本过长,在此不再赘述。