下面圖表示兩個表關系:
//表1User_invite
create table User_invite(
Invite_id INTEGER PRIMARY KEY, //注意:這里就代表是自動增長
user_id INTEGER,
Invite_date DATE ,
Invite_place VARCHAR(20) NOT NULL,
Invite_kind VARCHAR(20),
Invite_title VARCHAR(20),
Invite_other VARCHAR(50),
Invite_goodCount INTEGER,
Invite_talkCount VARCHAR(20),
Invite_enrollCount VARCHAR(20),
FOREIGN KEY (user_id ) REFERENCES User_info(user_id)); //注意這里:寫的外鍵要寫到最后,否則會出現Error: unknown column "user_id" in foreign key definition
故還有要先執行下面的
//必須在運行時打開, 因為 默認是關閉的
PRAGMA foreign_keys = ON;
//插入語句
insert into User_invite(user_id,Invite_date,
Invite_place,Invite_kind,
Invite_title,Invite_other,
Invite_goodCount,Invite_talkCount,
Invite_enrollCount)
values('1','2012-12-12','太原','輔導','輔導','無','1','很好','10');
//表2User_infor
create table User_info(
user_id INTEGER PRIMARY KEY,
user_name VARCHAR(50) NOT NULL ,
user_password VARCHAR(20) NOT NULL,
user_credit INTEGER,
user_sex VARCHAR(2),
user_age INTEGER,
User_constellation VARCHAR(50),
User_state INTEGER); //在線為1,離線為0 //用數字表示幾顆星,為信用標志
//插入語句
insert into User_info(user_name,user_password,user_credit, user_sex,user_age,User_constellation,User_state) values('xiaoming','123','5','男','22','無','1');
insert into User_info(user_name,user_password,user_credit, user_sex,user_age,User_constellation,User_state) values('張三','123','2','男','20','無','1');
update mytab set name='liming' where birthday='1992-12-12';
update mytab set name='zhangsan' where birthday='1993-10-12';
update mytab set name='wangwu' where birthday='1993-02-12';
update mytab set name='xiaoming' where birthday='1993-11-12';
====進入Android中的數據庫在cmd中敲這樣的命令(注意這里首先將模擬器打開或有真實的手機)======
adb shell
cd data/data/org.lxh.demo/databases
ls ---->查看當前的文件
sqlite3 xxx.db 即可
進入>sqlite
--------------
同時也可以用 命令 “.table” 查看已經建好的表,也可以”.schema“ 查看表的結構
--------------
插入數據后結果如下:
版權聲明:本文為博主原創文章,未經博主允許不得轉載。