1.创建表
CREATE TABLE TBL_BOOK(
ID INT NOT NULL,
TITLE VARCHAR2(100) NOT NULL,
AUTHER VARCHAR2(20),
PRICE NUMBER
);
2.插入项
INSERT INTO TBL_BOOK VALUES(1,’thurder,‘java’,200
);
INSERT INTO TBL_BOOK VALUES(1,’kitble’,‘bbbb’,100
);
commit;
3.修改项
UPDATE TBL_BOOK SET ID=2 WHERE TITLE=’SQL’;
commit;
4.查表
SELECT * FROM TBL_BOOK;
6增加列数
alter tableTBL_BOOK add pagenum int;
7删除列
alter table drop column pagenum;
8.增加主键值
alter table TBL_BOOK add constraintpk_tbl_book_id primary key (id);
9唯一索引
create unique index uni_isbn onbooks(isbn);
10,引用外键
userid int not null,
foreign key (userid) REFERENCES tbl_user(id),
一条语句插入多行数句
insertinto t1 (col1,col2,col3,…)
select ’’,’’,’’ from dualunion
select ’’,’’,’’ from dualunion
select ’’,’’,’’from dual
创建序列
-- Create sequence
create sequence STUDENT_SEQ
min value 0
max value 9999999999
start with 0
increment by 1
cache 2
cycle;
创建触发器,自动生成主键列值
create or replace trigger tablename_t before inserton tablename
for each row
begin
if inserting then
select table name_seq.nextval into :new.id fromdual;
end if;
end;