Mysql資料庫設計

來源:互聯網
上載者:User

標籤:

MYSQL資料庫設計

 

串逸出序列

\0 NUL(ASCLL 0)

\‘

\"

\b 退格

\n 新行

\r 斷行符號

\t 定位字元

\\ 反斜線

 

數值列類型

TINYINT 1位元組 非常小的整數 有符號值:-128至127 無符號值:0至255

SMALLINT 2位元組 較小的整數 有符號值:-32768

MEDIUMINT 3位元組 中等大小的整數 有符號值:

INT 4位元組 標準整數 有符號值:

BIGINT 8位元組 大整數 有符號值:

FLOAT 4位元組 單精確度浮點數 有符號值:

DOUBLE 8位元組 雙精確度浮點數 有符號值:

DECIMAL M位元組 一個串的浮點數 有符號值:

 

CHAR

VARCHAR

TINYBLOB

BLOB

MEDIUMBLOB

LONGBLOB

TINYTEXT

TEXT

MEDIUMTEXT

LONGTEXT

ENUM

SET

 

 

日期與時間類型格式

 

DATE "YYYY-MM-DD"

TIME "hh:mm:ss"

DATETIME "YYYY-MM-DD hh:mm:ss"

TIMESTAMP "YYYYMMDDhhmmss"

YEAR "YYYY"

 

數值列類型的取值範圍

 

 

數值列的列屬性:

AUTO_INCREMENT

建立一個唯一標誌符號或許順序值

create table a ( I int auto_increment not null primary key);

 

 

UNSIGNED

禁止此屬性存在負值

create table test(num tingint , num2 tingint unsigned);

 

 

NULL and NOT NULL

預設為NULL

 

create talbe test (num int, num2 int default 1, num3 int default null)

 

 

運算子

 

= 等於

 

<>或者!= 不等於

 

<=> NULL安全的等於(NULL-safe)

 

< 小於

 

> 大於

 

<= 小於等於

 

>= 大於等於

 

BETWEEN 存在與指定範圍

 

IN 存在於指點集合

 

IS NULL 為NULL

 

IS NOT NULL 不為NULL

 

LIKE 萬用字元匹配

 

REGEXP或者RLIKE Regex匹配

 

 

 

%(百分比符號)

a%b表示以a開頭b結尾的任意長度的字串

 

_(下橫線)

a_b表示以a開頭b結尾的長度為3的任一字元,

 

 

PRIMARY KEY

UNIQUE

NOT NULL

AUTO_INCREMENT

DEFAULT default_value

PRIMARY KEY 與UNIQUE

 

資料庫操作:

show database;

show tables;

use dataname;

create database 資料庫名;

create table test(

id int primary key auto_increment,

    title varchar(16)

);

 

describe 表名;

desc 表名;

drop talbe tablename;

alter talbe 表名 action

add 列名

add primary key 

alter 列名 set default

drop 列名

drop primary key 

drop index index_name

rename as 新表名

 

 

insert into 表名(id,name,...) valuse(1,liqingbo);

update 表名 set 列名=資料值 where 子句;

delet from 表名 where 子句;

select 

group by 

having

order by 

limit

desc asc

 

count sum avg max min

 

resource mysql_connect(host,root,password);

mysql_close();

bool mysql_select_db(tablename[,],串連返回變數);

resource mysql_query(SQL語句)

resource mysql_db_query(tablename[,]);

array mysql_fetch_row();

array mysql_fetch_array();

 

MYSQL_ASSOC:

MYSQL_NUM:

MYSQL_BOTH:

 

mysql_num_fields(); 取得結果集中欄位的數目

mysql_num_rows(); 取得結果集中行的數目

mysql_result();

mysql_free_result();

mysql_close();

mysql_pconnect;

mysql_create_db;

mysql_drop_db;

mysql_fetch_object;

mysql_affected_rows;

 

 

執行個體:

//建立資料庫連接

$link = mysql_connect("host","root","123456");

mysql_select_db("mytable",$link);

$sql = "select * from user ";

$send = mysql_query($slq);

while($row = mysql_fetch_row($sen)){

foreach($row as $v)

    {

    echo "$v";

    }

}

Mysql資料庫設計

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.