數(shù)據(jù)分析——SQL基礎(chǔ)知識(shí)概要介紹
CHAR():定長(zhǎng)字符串 最大長(zhǎng)度為 254
VARCHAR():變長(zhǎng)字符 最大長(zhǎng)度為 4000
SMALLINT:短整型數(shù)字 長(zhǎng)度為 2 字節(jié)
INTEGER:整型數(shù)字 長(zhǎng)度為 4 字節(jié)
REAL:?jiǎn)尉雀↑c(diǎn) 32 位近似值
DOUBLE:雙精度浮點(diǎn) 64 位近似值
DECIMAL(m,n):數(shù)字 精度為m小數(shù)位為n
DATE:日期時(shí)間
TIME:日期時(shí)間
TIMESTAMP:日期時(shí)間
CREATE:用于創(chuàng)建數(shù)據(jù)庫(kù)對(duì)象
DECLARE:除了是創(chuàng)建只在過程中使用的臨時(shí)表外,DECLARE語(yǔ)句和CREATE語(yǔ)句非常相似。唯一可以被聲明的對(duì)象是表。并且必須放入用戶臨時(shí)表空間
DROP:可以刪除任何用CREATE(數(shù)據(jù)庫(kù)對(duì)象)和DECLARE(表)創(chuàng)建的對(duì)象
ALTER:允許修改某些數(shù)據(jù)庫(kù)對(duì)象的信息。不能修改索引
(1)數(shù)據(jù)庫(kù)
CREATE DATABASE database-name [USING CODESET codeset TERRITORY territory]
drop database dbname
(2)表
創(chuàng)建新表:
create table tabname(col1 type1 [not null] [primary key],col2 type2 [not null],..)
根據(jù)已有的表創(chuàng)建新表:
create table tab_new like tab_old;create table tab_new as select col1,col2… from tab_old definition only
Alter table tabname add column col typeAlter table tabname add primary key(col)
Alter table tabname drop primary key(col)
drop table tabname
(3)表空間
創(chuàng)建表空間:
create tablespace tbsname pagesize 4k managed by database using (file ‘file’ size)
alter tablespace tablespace_name add(file 'filename' size)
drop tablespace tbsname
創(chuàng)建索引:
create [unique] index idxname on tabname(col….)
drop index idxname
(5)視圖
創(chuàng)建視圖:
create view viewname as select statement
drop view viewname(1)SELECT:從表中查詢符合數(shù)據(jù)
select時(shí),注意索引謂詞和非索引謂詞,盡量在有索引的列上使用索引謂詞。謂詞類型可索引注釋
(2)DELETE:刪除已有表的數(shù)據(jù)
DELETE FROM tablename WHERE (conditions)
(3)UPDATE:更新已有表的數(shù)據(jù)
UPDATE tabname SET (col1=values1,col2=values2,…) WHERE (conditions);
(4)INSERT:向已有表中插入數(shù)據(jù)
INSERT INTO tablename (col1,col2,…) VALUES (value1,value2,…);INSERT INTO tablename (col1,col2,…) VALUES (value1, value2,…), (value1, value2,…),……(1)GRANT—授予用戶權(quán)限
grant [all privileges|privileges,….] on tabname | viewname to [public|user,….]
(2)REVOKE—撤消用戶權(quán)限
Revoke [all privileges|privileges,….] on tabname | viewname from [public|user,….]
(3)COMMIT—提交事務(wù),可以使數(shù)據(jù)庫(kù)的修改永久化
commit [work]
(4)ROLLBACK—回滾事務(wù),消除上一個(gè)COMMIT命令后的所做的全部修改,使得數(shù)據(jù)庫(kù)的內(nèi)容恢復(fù)到上一個(gè)COMMIT執(zhí)行后的狀態(tài).。
ROLLBACK:將上次提交以來所做的更改全部撤消。語(yǔ)法格式:
Rollback [work]
點(diǎn)【點(diǎn)贊】【在看】為SQL加油↓↓
評(píng)論
圖片
表情
