sql: table-relation, row-tuple, column-attribute
一个table最多254个column
可使用的数据类型:
char( n长度的字符串),
varchar (不固定长度的字符串),
number(o,d)---o:总位数,d:小数点后位数:最大值:o=38, d=-84-127
date(日期型信息)-dd-mmm-yy
long--长字符串,每个table只许有一个long
*oraclc不支持bool型变量---可以用char1/number1模拟
注意:*表里的tuple出现顺序不相关
*一个表里不能有重复的tuple
orasql可接受的
对number型变量使用的数学运算:abs, cos, sin, exp, log, power, mod, sqrt, +;-;∗; /........
对char型变量的字符运算:chr,concat(string1, string2),lower, upper,replace(string, search string,replacement string), translate,substr(string, m, n),length,to date, . . .
对date型变量的日期运算:add month, month between, next day, to char, . . .
where语句可以用什么进行判定:=;!= or<>; <; >; <=, =>
in:判断是否属于......
null:是否是空集
between:可以对number和date型量进行判定
*aggregrate functions里:
max/min/sum/avg都不计算空值,但count计算
带primary key的列:主键必须包含唯一的值。 主键列不能包含 NULL 值。 每个表都应该有一个主键,并且每个表只能有一个主键。
其他约束:unique: 不能重复, not null: 非空
定义两个日期不能相同:
constraintno same datesunique(PEND, PSTART)ingredient
定义非空变量的初始值:
PSTARTdate default(’01-JAN-95’)
关键字:defult
做表之前需要检查:
What are the attributes of the tuples to be stored? What are the data types of the
attributes? Should
varchar2be used instead ofchar?
•Which columns build the primary key?
•Which columns do (not) allow null values? Which columns do (not) allow duplicates ?
•Are there default values for certain columns that allow null values ?
insert语法:分两种
insert intoPROJECT(PNO, PNAME, PERSONS, BUDGET, PSTART)
values(313, ’DBS’, 4, 150000.42, ’10-OCT-94’);
or
insert intoPROJECT
values(313, ’DBS’, 7411,null, 150000.42, ’10-OCT-94’,null)
query containing agroup byclause is processed in the following way:
1. Select all rows that satisfy the condition specified in the
whereclause.
2. From these rows form groups according to the
group byclause.
3. Discard all groups that do not satisfy the condition in the
havingclause.
4. Apply aggregate functions to each group.
5. Retrieve values for the columns and aggregations listed in the
selectclause.
网友评论