SQL> desc customers;
Name Type Nullable Default Comments
----------- ------------ -------- ------- --------
CUSTOMER_ID INTEGER
FIST_NAME VARCHAR2(10)
LAST_NAME VARCHAR2(10)
DOB DATE Y
PHONE VARCHAR2(12) Y
--向表中添加数据
insert into customers(customer_id,first_name,last_name,dob,phone) values(1,'John','Brown',date'1965-1-1','800-555-1211');
默认情况下,oracle的date类型格式为:DD-MM-YYYY,为了在添加和显示数据的时候我们能够更方便的查看数据,将其转化为我们所熟悉的YYYY-MM-DD格式,只要在添加数据时,在此列数据前面加上一个date关键字即可。
--向表中添加空值
insert into customers(customer_id,first_name,last_name,dob,phone)
values(3,'Steve','White',null,'800-555-1213');
--或者在表列中不指定此空列:
insert into customers(customer_id,first_name,last_name,phone)
values(4,'Steve','White','800-555-1213');
--删除空列
delete from customers where dob is null;
--约束分为列级约束和表级约束
--建purchaces表
create table purchases(
product_id integer
--列级约束
constraint purchases_fk_products
references products(product_id),
customer_id integer
constraint purchases_fk_customers
references customers(customer_id),
quantity integer not null,
--表级约束
constraint purchases_pk primary key (product_id,customer_id)
);