檢視資料表 show tables;
建立資料表
修改資料表-- 建立classes表(id、name)
create table classes(
id int unsigned not null auto_increment primary key,
name varchar(30)
);
重新命名表-- 修改表-新增字段
-- alter table 表名 add 列名 型別;
alter table students add birthday datetime [after 欄位名];
alter table students add birthday datetime [first];
-- 修改表-修改字段:不重新命名版
-- alter table 表名 modify 列名 型別及約束;
alter table students modify birthday date;
-- 修改表-修改字段:重新命名版
-- alter table 表名 change 原名 新名 型別及約束;
alter table students change birthday birth date default "2000-01-01";
-- 修改表-刪除字段
-- alter table 表名 drop 列名;
alter table students drop high;
-- 刪除表
-- drop table 資料表;
drop table ***xx;
rename table 舊表名 to 新錶名;
增加資料全部資料insert into table_name values(全部列的值);
部分字段insert into table_name (欄位1,欄位2) values (值1,值2);
插入多條insert into table_name values (全部列的值),(全部列的值),(全部列的值);
insert into table_name (欄位1,欄位2)values(值1,值2), (值1,值2), (值1,值2);
修改資料update table_name set xx = 值,yy = 值 where 條件;
刪除資料delete from table_name where 條件;
注意:在修改或者刪除資料的時候一定要指定條件,否則可能造成所有資料被汙染或者清空。
清空資料(會把全表都給清空掉,並且自增主鍵從1開始)truncate table_name;
查詢資料select * from table_name;
select * from table_name where 條件;
select 欄位as 別名 from table_name where 條件;
mysql資料表增刪改查
建立mysql資料表需要以下資訊 以下為建立mysql資料表的sql通用語法 create table table name column name column type 以下例子中我們將在 runoob 資料庫中建立資料表runoob tbl create table if not exists...
MySQL資料庫 資料表的增刪改查
mysql資料的增刪改查 crud 本文結構 一 增加 create 二 修改 update 三 查詢 retrieve 簡單查詢,下篇詳細展開 四 刪除 delete 首先,建立簡單的classes資料表和略微複雜的students資料表 id name age gender cls id bir...
資料表記錄的增刪改查
模型表資料的增刪改查 對資料庫內資料表中的表記錄進行操作 查 filter data models.user.objects.filter username username filter返回的結果是乙個 列表 裡面才是真正資料物件 filer括號內可以放多個關鍵字引數 這多個關鍵字引數在查詢的時候...