**的
今天覆習資料庫的sql,想著需要總結下各種資料庫的sql的不同點,供總結查閱,供別人參考!
1. sql server 的語法:
select top number|percent column_name(s)
from table_name2. mysql的語法:
select column_name(s)
from table_name
limit number3. oracle的語法:
select column_name(s)
from table_name
where rownum <= number注意:oracle rownum不支援">="
1. mysql:
create table persons
(
id_p int not null,
lastname varchar(255) not null,
firstname varchar(255),
address varchar(255),
city varchar(255),
unique(id_p)2. sql server / oracle / ms access:
create table persons
(
id_p int not null unique,
lastname varchar(255) not null,
firstname varchar(255),
address varchar(255),
city varchar(255)
)3. mysql / sql server / oracle / ms access:
create table persons
(
id_p int not null,
lastname varchar(255) not null,
firstname varchar(255),
address varchar(255),
city varchar(255),
constraint uc_personid unique (id_p,lastname)
)mysql / sql server / oracle / ms access:
alter table persons
add unique (p_id)
或
alter table persons
add constraint uc_personid unique (p_id,lastname)1. mysql:
alter table persons
drop index uc_personid2. sql server / oracle / ms access:
alter table persons
drop constraint uc_personid這裡只提供unique約束,primary key約束、foreign key約束、check約束類似。
·sql auto increment字段
1. mysql:
create table persons
(
p_id int not null auto_increment,
lastname varchar(255) not null,
firstname varchar(255),
address varchar(255),
city varchar(255),
primary key (p_id)
)2. sql server:
create table persons
(
p_id int primary key identity,
lastname varchar(255) not null,
firstname varchar(255),
address varchar(255),
city varchar(255)
)3.access:
create table persons
(
p_id int primary key autoincrement,
lastname varchar(255) not null,
firstname varchar(255),
address varchar(255),
city varchar(255)
)4. oracle:
create sequence seq_person
minvalue 1
start with 1
increment by 1
cache 10
insert into persons (p_id,firstname,lastname)
values (seq_person.nextval,'lars','monsen')1. sql server/ ms access
select productname,unitprice*(unitsinstock+isnull(unitsonorder,0))
from products2. oracle
select productname,unitprice*(unitsinstock+nvl(unitsonorder,0))
from products3.mysql
select productname,unitprice*(unitsinstock+ifnull(unitsonorder,0))
from products
或
select productname,unitprice*(unitsinstock+coalesce(unitsonorder,0))
from products
mysql和Oracle資料庫的不同點?
1.使用的索引結構不同 oracle b 樹索引,位圖索引 mysql innodb b 樹索引,hash索引,倒排序索引 2.使用索引搜尋資料的邏輯不一樣?mysql 在使用非主鍵索引進行查詢時,絕大數情況,通過輔助索引再到對應的主鍵值,然後通過聚集索引找到對應的資料。3.使用的語法上會有差別?a...
if和switch的不同點
1 if的括號內的表示式可以分別是布林型別的合法表示式 可以是所有大於0的正s整數為true,反之為小於等於0的正整數為false 可以是常量 列舉 而switch括號內也符合前面if提到的外,就是當圓括號內為正整數只能是0或1,其它的正整數屬於 default範圍。這點可以看如下 switch 2...
各種資料庫分頁的sql語句
1.oracle資料庫分頁 select from select a.rownum rc from 表名 where rownum endrow a where a.rc startrow 2.db2資料庫分頁 select from select rownumber over as rc,a.fr...