MYSQL資料庫基本語句

2021-08-07 01:54:08 字數 1462 閱讀 8509

sqlite3支援的型別:整數,文字,浮點,二進位制

sqlite3 ./test.sqlite      /*test.sqlite是資料庫的名字*/

.table  檢視資料庫中是否有表

/*建立表

no學號 整型 主鍵 自動增長的 不能為空

name姓名 文字 不能為空

age年齡 整型

*/create table student(no integer primary key autoincrement not null, name text\

not null, age integer);

//如果不存在建立

create table if not exists student(no integer primary key autoincrement notnull, name text \

not null, age integer);

//刪除表   如果沒有加;則表示輸入沒有結束

drop table student;

//向表中新增資料

insert into student(name, age) values('zhangsan', 12);

//檢視表中的所有列

select * from student;

//檢視name列

select name from student;

//按條件查詢

select * from student where age > 30;

//條件多個都要滿足用and,

select *from student where age >= 30 and no > 6;

//條件多個滿足其一即可用or,

select *from student where age >= 30 or no > 6;

//確定某個條件

select *from student where name = 'zhangsan' ;

//查處姓張的,%可以匹配乙個字元或者多個字元 '_'表示模糊匹配乙個字元

select *from student where name like 'zhang%' ;

//不是有zhang後面有兩個字元組成的

select *from student where name not like 'zhang__';

//刪除表中成員

delete from student where name='zhangsan';

//刪除所有姓張的

delete from student where name like 'zhang%';

//修改記錄

update student set name='bendan' where name='zhangsan';

//同時修改多條記錄

update student set name='test',age=10 where no=5;

MYSQL資料庫基本DDL語句

1 資料庫 檢視所有的資料庫 show databases 切換 選擇要操作 資料庫 use 資料庫名 建立資料庫 create database if not exists mydb1 charset utf8 刪除資料庫 drop database if exists mydb12 資料型別 i...

mysql資料庫基本操作語句

1 更改欄位名 change alter table student change column gradenews grade int 11 2 增加欄位和刪除字段 alter table student add column salary int 30 default 900000 alter ...

資料庫基本語句

資料庫很久沒用,忘的差不多了,練習一下。環境 mysql 表1表名 test1 屬性 id name,bookid 表二表名 book 屬性 id,name 1.建立資料庫 create database study1 2.建立表 create table test1 id int 11 not n...