1. 程式人生 > >關於數據庫的一些基本知識

關於數據庫的一些基本知識

操作系統 外模式 增加 管理數據 管理系 foreign 大量數據 排序 使用

Database:數據庫,是長期儲存在計算機內、有組織的、可共享的大量數據的集合。
DBMS:數據庫管理系統,是位於用戶與操作系統之間的一層數據管理軟件,用於科學地組織、存儲和管理數據、高效地獲取和維護數據。
DBS:數據庫系統,指在計算機系統中引入數據庫後的系統,一般由數據庫、數據庫管理系統、應用系統、數據庫管理員(DBA)構成。
數據庫的三級系統結構:外模式、模式和內模式。
主鍵:能夠唯一地標識一個元組的屬性或屬性組稱為關系的鍵或候選鍵。若一個關系有多個候選鍵則可選其一作為主鍵(Primary key)。
外鍵如果一個關系的一個或一組屬性引用(參照)了另一個關系的主鍵,則稱這個或這組屬性為外碼或外鍵(Foreign key)。

數據庫的操作:
查詢:select * from table_name
例:select * from student
修改:update table set row=value where row=value
例:update student set name=‘Mike‘ where name=‘John‘
增加:insert into table values(值1,值2,值3,...)
例:insert into student values(1,‘one’,25)
insert into student (id,name)values(1,‘one’);
刪除:delete from table where row=value
例:delete from student where name=‘one‘

like 與通配符(_和%)的使用
select * from student_1 where address like ‘%廣州市%‘
select * from student_1 where address like ‘___廣州%‘

distinct()去重函數;
select distinct(name) from student_1

排序:
降序:select * from student_1 order by id desc
升序:一般默認 select * from student_1 order by id asc

Alias(取別名):
select name "名字",age "年齡" from student_1

and:
select * from student_1 where age=20 and address like ‘廣東%‘

or:
select * from student_1 where address like ‘湖南%‘ or address like ‘湖北%‘

in:
select * from student_1 where age in(18,20)

between:
select * from student_1 where age between 18 an 19

隱藏列:rownum
可視化編輯:
select a. *,a.rowid from student_1 a;

刪除列中數據:
update table_name set 字段=null;
commit;

刪除整個列:
alter table 表名 drop column 列名;

插入一列數據:
alter table tablename add (columnname datatype);

關於數據庫的一些基本知識