一、表的創(chuàng)建
1、創(chuàng)建表
create if not exists ?table student(StuID integer);
2、 創(chuàng)建帶有缺省值的數(shù)據(jù)表:
create table if not exists ?schoolTable(schID integer default 0, schName varchar default 'hz');
3、if not exists 使用
?如果已經(jīng)存在表名、視圖名和索引名,那么本次創(chuàng)建操作將失敗。加上"IF NOT EXISTS"從句,那么本次創(chuàng)建操作將不會(huì)有任何影響.
create table if not exists studentTest(StuID integer);
4、primary key
create table if not exists ?studenttable (stuid integer primary key asc); 創(chuàng)建主鍵
create table if not exists?studenttable2 (stuid integer,stuName varchar, primary key(stuid,stuName)); 創(chuàng)建聯(lián)合主鍵
4 unique約束
create table if not exists?sutTest(stuID integer unique); 創(chuàng)建唯一性約束
5 check約束
create table if not exists?sutTest2(stuID integer, ID integer, check(stuID > 0 and ID <0));
?
二、表的修改
1、修改表名
alter table sutTest rename to stutest;
2、向表中添加新列
alter table??stuTest add column stuName varchar;
?
三、表的刪除
drop table if exists stuTest 如果某個(gè)表被刪除了,那么與之相關(guān)的索引和觸發(fā)器也會(huì)被隨之刪除。?
?
四、創(chuàng)建視圖
1、創(chuàng)建簡(jiǎn)單視圖
create view if not exists View_Corporate as select * from corporate where corid > 1
2、創(chuàng)建臨時(shí)視圖
create temp view tempView_Corporate as select * from corporate where corid > 1
?
五、刪除視圖
drop view if exists View_Corporate;
?
六、索引的創(chuàng)建
1、該索引基于corporate表的corID字段。
create index cor_index on corporate(corID);
2、該索引基于corporate表的corID,corname字段,,并且指定每個(gè)字段的排序規(guī)則
create index cor_index2 on corporate(corID asc, corName desc);
3、創(chuàng)建唯一索引
create unique index cor_index3 on corporate(corID asc, corName desc);
?
七、刪除索引
drop index if exists cor_index3;
?
八、重建索引 reindex;
?重建索引用于刪除已經(jīng)存在的索引,同時(shí)基于其原有的規(guī)則重建該索引。
九、數(shù)據(jù)分析 analyze;
十、數(shù)據(jù)清理 vacuum;
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號(hào)聯(lián)系: 360901061
您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對(duì)您有幫助就好】元
