2021年10月19日 星期二

04 SQL基本命令 以SQLite3為例 create table、 insert table 、 update 、select


介紹SQLite3

如何建立資料庫

如何建立表格結構

如何建立表格內資料

如何修正表格內資料

查詢資料

 

 

建(新增)

 

建立資料庫

$sqlite3 資料庫名.db

.open 資料庫名.db

建立table及結構

create table  table (欄名1  型態 ,欄名2  型態 ,);

>例

create table person ( name varchar(20) , tel varchar(15) , sex varchar(1) , salary integer );

建立單筆資料

insert into Table (欄名1,欄名2,欄名3 ,) values (欄名1內容,欄名2內容,欄名3內容,);

>例

insert into Table01 (name,email) values ('Jeannie','Jeannie@test.com') ;

 



顯示資料庫

database

顯示 table

table

顯示資料(查詢)

select 欄位1,欄位2, from Table ;

select * from Table ;

顯示符合條件資料(查詢)

select * from Table where 條件 ;

 



 

修改資料

update Table set 欄名=內容,欄名=內容, where 條件 ;

>例

update Table01 set name='Judy',email='Judy@test.com' where id='6‘ ;

 

 

£練習

1.建立 資料庫  testdb1

1.sqlite .open testdb1

sqlite .database

main: /home/bigred/testdb1

2.建立 table 取名 person

3.Person 內有以下欄位

name varchar(20)

tel varchar(15)

sex varchar(1)

salary integer

2.3.sqlite CREATE TABLE person ( name varchar(20) , tel varchar(15) , sex varchar(1) , salary integer );

sqlite .table

Person

4.新增對應的內容如下

4.sqlite insert into person (name , tel , sex , salary ) values ( 'name', '0911000111', 'M', 30000 ) ;

sqliteselect * from person ;

name|0911000111|M|30000

sqlite insert into person ( name,tel ,sex ,salary ) values ( 'marry' , '0922000222' ,'F' ,25000);

sqlite select * from person ;

name|0911000111|M|30000

marry|0922000222|F|25000

sqlite insert into person (name ,tel,sex,salary) values ( 'lee' ,'0933000333' , 'N' ,33000 );

sqlite select * from person ;

name|0911000111|M|30000

marry|0922000222|F|25000

lee|0933000333|N|33000

sqlite insert into person (name,tel,sex,salary) values ('wang','0944000444','M',50000);

5.顯示所有欄位內容

5.sqlite select * from person ;

name|0911000111|M|30000

marry|0922000222|F|25000

lee|0933000333|N|33000

wang|0944000444|M|50000

6.顯示 namesalary 內容

6.sqlite select name,salary from person;

name|30000

marry|25000

lee|33000

wang|50000

7.顯示 性別為 (M)的資料

7. sqlite select * from person where sex="M";

name|0911000111|M|30000

wang|0944000444|M|50000

8.顯示 性別為 (M)的姓名(name)與電話(tel)

8.sqlite select name ,tel from person  where sex='M';

name|0911000111

wang|0944000444

9.顯示薪水超過32000的資料

9. sqlite select * from person where salary 32000 ;

lee|0933000333|N|33000

wang|0944000444|M|50000

10.將姓名lee 的人,性別變更為M

10.sqliteupdate person set sex="M" where name="lee" ;

sqlite select * from person;

name|0911000111|M|30000

marry|0922000222|F|25000

lee|0933000333|M|33000

wang|0944000444|M|50000

11.將姓名name 的人, 變更為john

11.sqlite update person set name='john' where name ='name';

sqlite select * from person;

john|0911000111|M|30000

marry|0922000222|F|25000

lee|0933000333|M|33000

wang|0944000444|M|50000

 

相關演講:

20211004社群行銷之客戶關係管理

https://youtu.be/goWBKR7fLqw

 

相關單元:

mariaDB (10.6.4:視窗版)下載與安裝

https://youtu.be/SIKYgvWhNkk

資料庫DATABASE相關專有名詞介紹-RDBMSDBMSdatabasetablerecordfieldPrimary KeyForeign keydatabase normalizationFirst normal form1NF)、2NF

https://youtu.be/-lpbA1pjPzs

 

 

相關活動:

▶▶▶▶▶▶▶▶活動資訊

臺灣雲市集 TCloud 計畫

最高可獲政府補助點數 30,000

1 = 新臺幣 1

叡揚雲端方案連結

https://reurl.cc/a9RVvQ

 

線上講座_找對雲端工具包,打造營運新活水

叡揚資訊 雲端及巨資事業群

賴俊仁 處長

https://reurl.cc/AkpA7Z

 

 

 

 

 

 

#database#table#Record#field#primary key#Foreign Key#First normal form1NF#DBMS(DataBase Management System)#RDBMS(Relational DataBase Management System)#database normalization#關聯式資料庫管理系統#資料庫管理系統#資料庫#表格#記錄#欄位#第一階正規化#第二階正規化#資料庫正規化#主鍵#外鍵#ACCESS#MYSQL#MariaDB#SQLite3


沒有留言:

張貼留言

如何免費增加monica AI使用次數

⚡chrome 線上應用程式商店-Monica-ChatGPT4驅動的AI Copilot https://chromewebstore.google.com/detail/monica-your-ai-copilot-po/ofpnmcalabcbjgholdjcjblkibo...