今天來學資料庫相關的語法
在 Android 中,通常使用 SQLite 來作為內嵌資料庫
練習相關的語法
CREATE TABLE IF NOT EXISTS user_info(
_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
name VARCHAR NOT NULL,
age INTEGER NOT NULL,
height LONG NOT NULL,
weight FLOAT NOT NULL,
married INTEGER NOT NULL,
update_time VARCHAR NOT NULL);
DROP TABLE IF EXISTS user_info;
ALTER TABLE user_info ADD COLUMN phone VARCHAR;
INSERT INTO user_info(name,age,height,weight,married,update_time) VALUES('張三',60,170,68,1,'20241209');
INSERT INTO user_info(name,age,height,weight,married,update_time) VALUES('李四',35,175,60,0,'20241209');
INSERT INTO user_info(name,age,height,weight,married,update_time) VALUES('王五',18,189,70,0,'20241209');
DELETE FROM user_info WHERE name='張三';
UPDATE user_info SET married=1 WHERE name='王五';
SELECT married FROM user_info WHERE name='王五';
SELECT * FROM user_info ORDER BY age ASC;
SELECT * FROM user_info ORDER BY age DESC;
學會基本使用之後 就可以在android裡用資料庫啦