MySQL表資料的增刪改查

2021-07-15 22:38:08 字數 2291 閱讀 8724

mysql入門(三)

1)、查詢所有行

命令: select 《欄位1,欄位2,...> from < 表名 > where < 表示式 >

例如:檢視表myclass 中所有資料

mysql> select * from myclass;

2)、查詢前幾行資料

例如:檢視表myclass 中前2行資料

mysql> select * from myclass order by id limit 0,2;

select一般配合where使用,以查詢更精確更複雜的資料。3)、

一使用select

子句進行多表查詢

select欄位名 from 表1,表2 … where 表1.欄位 = 表2.欄位 and 其它查詢條件

例如:

select a.name,a.address,b.math,b.english,b.chinese

from tb_demo0

1as b,tb_demo0

2as a

where a.id=b.id

語法:update 表名 set 字段=新值,… where 條件

mysql> update myclass set name='mary' where id=1;

例子1:單錶的mysql update語句:

update [low_priority] [ignore] tbl_name setcol_name1=expr1 [, col_name2=expr2 ...] [wherewhere_definition] [order by ...] [limit row_count]

例子2:多表的update語句:

update [low_priority] [ignore] table_references

set col_name1=expr1 [, col_name2=expr2 ...] [wherewhere_definition]

update語法可以用新值更新原有錶行中的各列。set子句指示要修改哪些列和要給予哪些值。where子句指定應更新哪些行。如果沒有where子句,則更新所有的行。如果指定了order by子句,則按照被指定的順序對行進行更新。limit子句用於給定乙個限值,限制可以被更新的行的數目。

insert

[low_priority |delayed| high_priority]

[ignore]

[into]tbl_name [(col_name,...)]

values(,...),(...),...

[ onduplicate key update col_name=expr, ... ] 或:

insert

[low_priority |delayed| high_priority]

[ignore]

[into]

tbl_name

setcol_name

=, ...

[ onduplicate key update col_name=expr, ... ] 或:

insert

[low_priority|high_priority]

[ignore]

[into]tbl_name [(col_name,...)]

select

...

[ onduplicate key update col_name=expr, ... ]

單錶語法:

delete

[low_priority] [quick] [ignore] from tbl_name 

[where

where_definition]  

[order

by ...]  

[limit

row_count] 

多表語法:

delete

[low_priority] [quick] [ignore] 

tbl_name[.*]

[, tbl_name[.*] ...] 

from

table_references  

[where

where_definition]  或:

delete

[low_priority] [quick] [ignore] 

from

tbl_name[.*] [, tbl_name[.*] ...] 

using

table_references  

[where

where_definition]

mysql增刪改查鍊錶 鍊錶的增刪改查

include include 先定義鍊錶裡面的元素。typedef struct nodemynode 定義整個鍊錶。typedef struct linkmylink int isempty to mylink mylink mylink 判斷鍊錶是否為空。int push to mylinki...

mysql 表的增刪改查

1.建立表 create table 表名 欄位名1 型別 寬度 約束條件 欄位名2 型別 寬度 約束條件 欄位名3 型別 寬度 約束條件 1.在同一張表中,欄位名不能相同 2 寬度和約束條件可選 3.欄位名和型別是必須的 2.檢視表 檢視表結構 desc 表名 檢視表的詳細資訊 show crea...

mysql資料表增刪改查

建立mysql資料表需要以下資訊 以下為建立mysql資料表的sql通用語法 create table table name column name column type 以下例子中我們將在 runoob 資料庫中建立資料表runoob tbl create table if not exists...