3.1、創(chuàng)建表
          格式:create table 表名;

          3.2、刪除表
          格式:drop table 表名;

          3.3、創(chuàng)建臨時(shí)表
          格式:create gkoabl temporary table temp
          AS
          select Name,PhoneNo from friend;

          3.4、復(fù)制表
          格式:create table My_friend AS select*from friend;

          3.5 、創(chuàng)建非空約束 ( not null )

          3.6、指定默認(rèn)值 ( default '默認(rèn)值內(nèi)容' )

          3.7、設(shè)定主鍵 ( primary key )

          3.8、設(shè)置唯一約束 ( 語(yǔ)句后面加 unipue )

          3.9、設(shè)置檢查約束
          格式:age int check(age between 20 and 50);
          或 sex varchar check(sex in ('男','女'));

          3.10 、使用序列 ( sequences)
          格式:
          create sequences friendidseq;
          (序列的初始值為1,增量為1)

          create sequences friendidseq increment by 1
          start with 1000;
          (序列的初始值為1000,增量為1)
          顯示最后一個(gè)序列值
          select friendidseq.currval from dual;

          3.11、使用自動(dòng)編號(hào)字段
          格式:create sequences seq;

          create or replace trigger autonumber
          before insert on friend
          for each row
          begin
          select seq.nextval
          into :new.friendid from dual;
          end;

          3.12、外鍵約束
          關(guān)鍵字:constraint?? foreign key()
          ?????????????????references?
          舉例
          ?????????create???table???student(
          ?????????studentid?? int???not?? null???primary?? key,
          ?????????name???varchar(20)?? not?? null
          ?????????);
          ?????????
          ?????????create???table???phone(
          ?????????phoneid???int???not???null???primary?? key,
          ?????????studentid?? int???not???null,
          ?????????phone?? varchar(14),

          ?????????constraint?? fid_fk???foreign???key(srudentid)
          ?????????????references????student(studentid)????????
          ?????????)?;

          3.13、創(chuàng)建索引
          ?????????格式:create???index???nameindex?? on?? student (name);???(創(chuàng)建非唯一索引)
          ?????????????????????create???unique???index???nameindex???on???student(name);???(創(chuàng)建唯一索引)??
          ?????????????????????
          ????????查詢索引:
          ??????????????????????select???student.name???from???student???where???name = '但是';????
          ??
          ??????????????????????select???student.name???from???student???where???name =??'%電'?;
          ??????? 刪除索引
          ????????????????????? drop???index???nameindex;???
          ???????????????

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 易门县| 临沂市| 宣武区| 民丰县| 昌江| 米泉市| 岐山县| 广宗县| 蕉岭县| 吉安市| 洛川县| 泗阳县| 巴东县| 建水县| 潼关县| 石泉县| 宣威市| 汉中市| 紫阳县| 璧山县| 密云县| 台北市| 泸水县| 罗田县| 汾阳市| 苗栗市| 阳山县| 铁岭市| 镇巴县| 崇州市| 凌源市| 桂东县| 轮台县| 广汉市| 卓资县| 上蔡县| 绥德县| 涞水县| 克山县| 兴国县| 淮阳县|