1、拷贝一个新表

create table test2 as (select * from test where 1=2);

2、建立新表,并把数据拷贝入新表中(适应SqlServer数据库)

select * into book2 from book;

 

3、自动增长列

--SqlServer

create table student(
  --自动增长列
  id int identity(1,1),
  name varchar(50)
);

--Oracle

--序列
create sequence seq_stu
increment by 1
start with 1
/
--触发器
create trigger tri_stu
before insert on student
referencing
new as new_value
for each row
begin
  select seq_stu.NEXTVAL
  into :new_value.stuId
  from dual;
end;
/

4、更改列

--增加列
alter table stu2
add stuName varchar(20);
--删除列
alter table stu2
drop column stuName;
--修改列
alter table stu2
alter column stuName varchar(50);

5、函数 Null值判读

--如果是Null则是0 (SQL Server / MS Access)
select isNull(stuAge,0) from student;
--Oracle NVL()
select NVL(stuAge,0) from student;
--MySql ifNull()
select ifNull(stuAge,0) from student;

6、行号

Oracle:     select RowNum,id from student;

Sql Server: select row_number()over(order by id) as RowNum,id from student;

 

 

相关文章:

  • 2022-12-23
  • 2021-11-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-22
  • 2021-07-27
  • 2021-12-17
猜你喜欢
  • 2022-02-16
  • 2022-12-23
  • 2022-12-23
  • 2021-10-09
  • 2022-01-06
  • 2022-02-05
  • 2021-09-15
相关资源
相似解决方案