sql語言,sqlite資料庫
阿新 • • 發佈:2018-12-10
資料庫: 資料庫是按照一定規則來管理資料的倉庫. 資料庫用的最多的就是增刪改查
sql 語言
sqlserver mysql oracle sqlite
資料庫 是一個檔案櫃 資料庫裡面儲存資料表 資料表儲存詳細資料 資料表有結構 資料行成為記錄
drop: 表 庫 delete: 記錄 #軟體安裝 軟體解壓後SQLite\SqliteLite\sqlite-tools-win32-x86-3210000\sqlite-tools-win32-x86-3210000,把這三個快捷方式複製出來放進一個資料夾,然後把SQLiteStudio也解壓出來, 需要配置環境變數: 我的電腦右鍵屬性,高階系統設定,環境變數,找到path選中,點編輯,然後在後邊加上之前複製出來的三個快捷方式的資料夾路徑加在後邊即可,然後運行復製出來的快捷鍵中的sqlite3 #程式碼執行,資料的增刪改查
--建立資料庫
--sqlite3 dbname.db
-- 資料庫的字尾.db
--使用sqlite studio 建立資料庫
--開啟資料庫
.open dbname.db
--建立資料表
-- int float double string char
integer int
real double
text 文字 string
int --> int
char(1) --> char
varchar(N)/char(N) --> string
float --> float
--建立一個學生資訊表
-- stuid name sex age phone email
-- varchar(30) varchar(10) char int char(11) varchar(50)
create table stuinfo
(
id varchar(30) primary key not null,
name varchar(10) not null,
sex char(1) default '男',
age int,
phone char(11) unique ,
email varchar(50) unique
);
--刪除表
drop table stuinfo;
--檢視所有資料表
.tables
--檢視資料庫
.databases
--一張完整的資料表只能必須有一個主鍵 主鍵是一個唯一能夠區分一條記錄的表頭項
primary key --主鍵
not null -- 某一列不能為null
default: -- 預設
unique: --唯一
-- .schema table name 查看錶結構
--插入資料
insert into stuinfo values() -- 按照預設的順序依次插入
insert into stuinfo(sex, age, name) values() -- 按照約定好的順序插入資訊
insert into stuinfo values
('180703','張三瘋','男',20,'13245678903',' [email protected]'),
('180704','李思思','女',18,'13245678904','[email protected]'),
('180705','王汙汙','男',45,'13245678905','[email protected]'),
('180706','趙六六','女',20,'13245678906','[email protected]'),
('180707','呵呵噠','男',18,'13245678907','[email protected]'),
('180708','巴扎黑','女',16,'13245678908','[email protected] '),
('180709','select','男',18,'13245678909','[email protected]'),
('180710','update','男',15,'13245678910','[email protected]');
insert into stuinfo(age,email,phone,id,name)
values(18,'[email protected]','13245678902','180702',"王哈哈");
-- 這樣做法是錯誤的 主鍵不能為null 在工程開發中主鍵必定是唯一的
insert into stuinfo(age,email,phone,name)
values(19,'[email protected]','13245678904',"呵呵噠");
--查詢 萬用字元 就是all 列
select * from stuinfo;
select id, name, sex from stuinfo;
select * from stuinfo where sex != '女' or age = 18;
delete from stuinfo where age = 45;
delete from stuinfo;
update stuinfo set age = 1000 where name = '李思思' or sex = '男';
select * from stuinfo where age > 1000;