CSDN博客

img yangdongxin

在Oracle、MySQL、MS SQL Server中查询指定数目的记录

发表于2008/10/1 17:37:00  516人阅读

OracleMySQLMS SQL Server中查询指定数目的记录

Oracle

创建一个t_user表:

create table t_user(
       id number primary key,
       userName varchar2(
15
) not null unique,
       userPass varchar2(
20
)
);

create sequence seq_user_id
start with
1

increment by
1;

create trigger tr_user_id
before
insert
on t_user
for each row
begin
     select seq_user_id.nextval into :new.id from dual;
end;

insert into t_user (userName,userPass) values('handson','handson');

insert into t_user (userName,userPass) values('admin','admin');
insert into t_user (userName,userPass) values('yangdongxin','pass');

select * from t_user;

 

select * from t_user where rownum<=2;--rownumOracle中的一个隐藏字段,用来记录记录数

 

 

MySQL

create database user_db;

use user_db;

create table t_user(

  id int primary key auto_increment,

  userName varchar(15) not null unique,

  userPass varchar(20)

 );

 

insert into t_user (userName,userPass) values('handson','handson')

,('admin','admin'),(‘yangdongxin’,’pass’);

 

select * from t_user;

select * from t_user limit 2;--取前2个记录

select * from t_user limit 1,2;--从第2条记录开始取,取2条记录(注意:索引是从0开始

 

 

MS SQL Server

create table t_user(

  id int primary key identity(1,1),

  userName varchar(15) not null unique,

  userPass varchar(20)

 )

 

insert into t_user (username,userPass) values('handson','handson')

insert into t_user (username,userPass) values('admin','admin')

insert into t_user (username,userPass) values('yangdongxin,'pass')

 

select * from t_user

 

select top 2 * from t_user—取前2条记录

 

阅读全文
0 0

相关文章推荐

img
取 消
img