1
、介绍 数据库,数据表,记录,字段,和对数据表的操作增删改(create,alter,drop)
下面针对具体的表来说明一下:
#sysplus /nolog
SQL>startup
SQL>conn /as sysdba
#查看oracle现有账号
SQL> select username,account_status from dba_users;
#下面用SCOTT账号进行演示操作,
#oracle 11.2默认锁定SCOTT,需要解锁
SQL> alter user scott account unlock;
#设置scott账号密码为tiger
SQL>alter user scott identified by tiger;
#重新输出一下现有oracle账号,发现scott已经open
SQL> select username,account_status from dba_users;
#用scott连接
SQL> conn scott/tiger
Connected.
#查看当前用户
SQL> show user
USER is "SCOTT"
create创建#scott默认有四个表,新建一个学生表
SQL> create table students(id integer,name varchar(25));
Table created.
#查看学生表字段类型
SQL> DESC students
Name Null? Type
----------------------------------------- -------- ----------------------------
ID NUMBER(38)
NAME VARCHAR2(25)
insert into插入#插入3条记录
SQL> insert into students values(1,'Jason');
SQL> insert into students values(2,'Charley');
SQL> insert into students values(3,'Evan');
#插入其中2个字段的值
SQL> INSERT INTO xue_sheng(id,nian_ling) VALUES(4 , 25);
#输出表中所有记录
SQL> select * from students;
ID NAME
---------- -------------------------
1 Jason
2 Charley
3 Evan
alter增加字段#在现有表中增加字段,修改操作ALTER,
SQL> ALTER TABLE students ADD age number;
Table altered.
update 更新数据
#更新3条记录
SQL> update students set age=27 where id=1;
SQL> update students set age=30 where id=2;
SQL> update students set age=21 where id=3;
输出表
delete from删除记录
SQL> delete from students where id=4;
alter drop删除字段
#删除年龄字段
SQL> alter table students drop column age;
drop table 删除表
SQL>drop table students;
2、字段数据类型