zoukankan      html  css  js  c++  java
  • 自己总结一些操作数据库的方法

    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;

  • 相关阅读:
    cpp 模版函数
    叉积
    利用scrollTop 制作图片无缝滚动
    事件绑定和时间取消
    闭包写法
    增加类,删除类,查找类
    获取元素到页面上的位置
    在IE8中如何通过javascripts改变<style />中的内容?
    有关app的一些小知识
    获取页面高宽知识
  • 原文地址:https://www.cnblogs.com/wangcq/p/3467442.html
Copyright © 2011-2022 走看看