数据库

上一篇 / 下一篇  2017-03-14 10:39:08

SQL增删改查
  一、数据定义语言 DDL:创建、修改、删除数据库语言。
create table Student
(
sno       varchar2(3) not null,
sname     varchar2(8) not null,
ssex      varchar2(2) not null,
sbirthday date,
sclass    varchar2(5)
)
;
-- Add comments to the table
comment on table Student
is '学生表';
-- Add comments to the columns
comment on column Student.sno
is '学号(主建)';
comment on column Student.sname
is '学生姓名';
comment on column Student.ssex
is '性别';
comment on column Student.sbirthday
is '生日';
comment on column Student.sclass
is '班级';
  二、数据操作语言 DML:添加(insert into)、修改(update   set)、删除表中的数据。(delete)
  1.数据的添加:
  --增加数据
  insert into student(sno,sname,ssex) values('102','张三','男');
  --或者这样写
  insert into student values('102','张三','男',sysdate,'95033');
  select * from student
  2.数据的修改:
  --数据的修改
  update student set ssex='女' where sno='102';
  --如果不加where,便是修改整个表某列的属性
  --对某一列数据的加减
  update student set sclass=sclass+1;
  update 表名 set 列名=列名+1 where 条件
  --日期的加减1为日的加减1
  3.数据的删除:
  --数据的删除
  delete student where sno=102;
  delete 表名 where 条件;
  --不加where,即删除整个表,但是效率低,可用truncate table 表名来删除(先删表,再建表)
  例:truncate table student;
  三、数据查询语言 DQL:从表中获取数据(查询数据)。
  --数据查询
  select * from student;
  select * from 表名;
  --根据条件找字段
  select sno,sname from student where sclass='95031';
  select 字段名 from 表名 where 条件
物理删除与逻辑删除
  1. 物理删除记录,即是会将数据库中的数据记录直接清除(也可以说是磁盘上的删除),会释放出物理空间,也将不能再从数据库中搜索到删去的数据记录;数据库中使用delete语句的删除就是物理删除

  2. 逻辑删除记录,不会直接删除数据库中的数据,仅是通过某些手段屏蔽被逻辑删除的数据在前台的显示,不会释放物理空间,并且还可以从数据库中查得数据。


TAG: 数据库

 

评分:0

我来说两句

我的栏目

日历

« 2024-04-18  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 18059
  • 日志数: 9
  • 建立时间: 2013-07-04
  • 更新时间: 2019-05-28

RSS订阅

Open Toolbar