當前位置:才華齋>計算機>計算機三級>

計算機三級資料庫技術SQL基礎知識點

計算機三級 閱讀(3.22W)

導語:SQL是一種特殊目的的程式語言,是一種資料庫查詢和程式設計語言,用於存取資料以及查詢、更新和管理關係資料庫系統;同時也是資料庫指令碼檔案的副檔名。下面是計算機三級資料庫技術SQL基礎知識點,一起來學習下吧:

計算機三級資料庫技術SQL基礎知識點

1、說明:建立資料庫

CREATE DATABASE database-name

2、說明:刪除資料庫

drop database dbname

3、說明:備份sql server

--- 建立 備份資料的 device

USE master

EXEC sp_addumpdevice 'disk', 'testBack', 'c:mssql7backupMyNwind_'

--- 開始 備份

BACKUP DATABASE pubs TO testBack

4、說明:建立新表

create table tabname(col1 type1 [not null] [primary key],col2 type2 [not null],..)

根據已有的表建立新表:

A:create table tab_new like tab_old (使用舊錶建立新表)

B:create table tab_new as select col1,col2… from tab_old definition only

5、說明:刪除新表

tabname

6、說明:增加一個列

Alter table tabname add column col type

注:列增加後將不能刪除。DB2中列加上後資料型別也不能改變,唯一能改變的是增加varchar型別的.長度。

7、說明:新增主鍵: Alter table tabname add primary key(col)

說明:刪除主鍵: Alter table tabname drop primary key(col)

8、說明:建立索引:create [unique] index idxname on tabname(col….)

刪除索引:drop index idxname

注:索引是不可更改的,想更改必須刪除重新建。

9、說明:建立檢視:create view viewname as select statement

刪除檢視:drop view viewname

10、說明:幾個簡單的基本的sql語句

選擇:select * from table1 where 範圍

插入: into table1(field1,field2) values(value1,value2)

刪除: from table1 where 範圍

更新:table1 set field1=value1 where 範圍

查詢:select * from table1 where field1 like ’%value1%’ ---like的語法很精妙,查資料!

排序:select * from table1 order by field1,field2 [desc]

總數:select count as totalcount from table1

求和:select sum(field1) as sumvalue from table1

平均:select avg(field1) as avgvalue from table1

最大:select max(field1) as maxvalue from table1

最小:select min(field1) as minvalue from table1