การสร้าง column’

Untitled

Untitled

varchar เป็นString ช่องว่างให้เท่าที่ใช้ จะตัดส่วนที่เราจองเกินไว้

ถ้า char ถ้าจอง 20 ใช้เท่าไหร่ก็จะเป็น 20

unique ห้ามซ้ำ

not null ห้ามว่าง

Untitled

default ค่าตั้งต้น

drop table เป็นการลบ ตาราง

**create table customer
(
    cust_no number(5) primary key,
    name char(20) not null,
    address varchar(40) not null,
    dob date,
    id_card_no number(13)	unique,
    char_type char(1)
)
--table column constrain
create table customer_1
(
    cust_no number(5) primary key,
    name char(20) not null,
    address varchar(40) not null,
    dob date,
    id_card_no number(13)	unique,
    cust_type char(1)	check( cust_type in ('A','B','C'))
)
--table table constrain
create table customer_2
(
    cust_no number(5),
    name char(20) not null,
    address varchar(40) not null,
    dob date,
    id_card_no number(13),
    cust_type char(1),

    primary key(cust_no),
    unique(id_card_no),
    check(cust_type in ('A','B','C'))
)**

เป็น order

create table order_1(
    ord_no number(5) primary key,
    ord_date date default sysdate not null,
    amount number(9,2) not null,
    cust_no number(5) references customer_1(cust_no) --data typeต้องเหมือนกันเป็น foreign key
)

create table order_2(
    ord_no number(5) ,
    ord_date date default sysdate not null,
    amount number(9,2) not null,
    cust_no number(5),

    primary key(ord_no),
    foreign key(cust_no) references customer_2(cust_no)
)

ex#1

create table suppliers(
    supplier_id number(10) not null,
    name varchar(50) not null,
    address varchar(50),
    
    primary key(supplier_id)
)

ex#2

create table customers(
    customer_id number(10) not null,
    customer_name varchar(50) not null,
    age number(2),

    primary key(customer_id)
)

ex#3

create table depts(
    dept_id number(4),
    dept_name varchar(30),
    primary key(dept_id)
);
create table emps(
    employee_number number(10),
    employee_name varchar(50),
    department_id number(4),
    salary number(6),

    foreign key(department_id) references depts(dept_id) --data typeต้องเหมือนกันอย่างในที่นี้ ที่เหมือนกันคือ number(4)
)

สร้างตารางใหม่ โดยใช้ข้อมูลโดยใช้ข้อมูลจากตาราง select