mysql控制access mysql 表操作

2021-10-17 22:02:13 字數 2369 閱讀 1197

建立表

簡單的方式

create table person (

number int(11),

name varchar(255),

birthday date

或者是create table if not exists person (

number int(11),

name varchar(255),

birthday date

檢視mysql建立表:

show create table person;

create table `person` (

`number` int(11) default null,

`name` varchar(255) default null,

`birthday` date default null

) engine=myisam default charset=utf8;

檢視表所有的列:

show full columns from person;

| field | type | collation | null | key | default | extra | privileges | comment |

| number | int(11) | null | yes | | null | | select,insert,update,references | |

| name | varchar(255) | utf8_general_ci | yes | | null | | select,insert,update,references | |

| birthday | date | null | yes | | null | | select,insert,update,references | |

建立臨時表

create temporary table temp_person (

number int(11),

name varchar(255),

birthday date

create table if not exists person2 (

number int(11),

name varchar(255),

birthday date

注意,原有表的結構與create table語句中表示的表的結構是否相同,這一點沒有驗證。注釋:如果您在create table...select語句中使用if not exists,則不論表是否已存在,由select部分選擇的記錄都會被插入。

在create table語句的末尾新增乙個select語句,在乙個表的基礎上建立表

create table new_tbl select * from orig_tbl;

注意,用select語句建立的列附在表的右側,而不是覆蓋在表上

mysql> select * from foo;

| n |

| 1 |

mysql> create table bar (m int) select n from foo;

mysql> select * from bar;

| m | n |

| null | 1 |

也可以明確地為乙個已生成的列指定型別

create table foo (a tinyint not null) select b+1 as a from bar;

根據其它表的定義(包括在原表中定義的所有的列屬性和索引),使用like建立乙個空表:

create table new_tbl like orig_tbl;

建立乙個有主鍵,唯一索引,普通索引的表:

create table `people` (

`peopleid` smallint(6) not null auto_increment,

`firstname` char(50) not null,

`lastname` char(50) not null,

`age` smallint(6) not null,

`townid` smallint(6) not null,

primary key (`peopleid`),

unique key `unique_fname_lname`(`firstname`,`lastname`),

key `fname_lname_age` (`firstname`,`lastname`,`age`)

其中peopleid是主鍵,以firstname和lastname兩列建立了乙個唯一索引,以firstname,lastname,age三列建立了乙個普通索引

刪除表drop table tbl_name;

或者是drop table if exists tbl_name;

mysql 併發控制 mysql併發控制

mysql併發控制 當有多個查詢需要同時修改同乙個資料,就會產生併發控制的問題。mysql可以在兩個層面進行併發控制 伺服器層和儲存引擎層。mysql通過加鎖實現併發控制 鎖有兩類 讀鎖 共享鎖,即乙個讀鎖不會阻塞其它讀鎖,多個使用者可同時讀取同乙個資源,而不互相干擾。寫鎖 排他鎖,即乙個寫鎖會阻塞...

mysql報表控制語句 mysql控制語句

mysql中的使用者資訊都儲存在系統資料庫mysql的user表中 建立使用者 create user 使用者名稱 允許其登入的位址 identified by 密碼 刪除使用者 drop user 使用者名稱 允許其登入的位址 修改使用者密碼 修改自己密碼 set password passwor...

mysql流控制 mysql 控制流函式

ifnull expr1,expr2 如果 expr1 為非 null 的,ifnull 返回 expr1,否則返回 expr2。ifnull 返回乙個數字或字串值 mysql select ifnull 1,0 1 mysql select ifnull null,10 10 如果 expr1 e...