mysql基本總結

來源:互聯網
上載者:User

標籤:mysql基礎

建立資料庫
creat table test(
#整數通常使用int
test_id int,
#小數通常使用decimal
test_price decimal,
#普通文本通常使用,並使用Default指定預設值
test_name varchar(255) default "Xxx",
#大文本類型使用test
test_desc text,
#圖片使用blob
test_img blob,
#日期類型使用DateTime
test_date datetime,
);
-----------------------------------------------------------------
mysql 支援的列類型
1.tinyint,smallint,mediumint,int,bigint
2.float,double
3.decimal(dec)
4.date
5.time
6.datetime
7.timestamp
8.year
9.char
10.varchar
11.binary(定長的二進位字串類型,以二進位形式保


存字串)
12.varbinary
13.tinyblob,blob,mediumblob,longblob
14.tinytext,text,mediumtext,longtext
15.enum(‘value1‘,‘value2‘...)//枚舉類型(只能是其中


之一)
16.set(‘value1‘,‘value2‘...)//集合類型(可以是其中幾


個)
--------------------------------------------------------------------
#建立資料表,該資料表和user_info完全相同,資料


也完全相同
create table hehe
as
select * from user_info;
---------------------------------------------------------------------
#修改表的結構的文法
alert table 表名
add(
#可以定義多個列定義
colum_name datatype [default expr],
...
);
---------------------------------------------------------------------
#為hehe資料表增加一個hehe_id欄位,該欄位類型為


int


alter table hehe
add hehe_id int;
#為hehe資料包增加aaa,bbb欄位,兩個欄位的類型都


為varchar(25)
alter table hehe
add aaa varchar(25),bbb varchar(25);
----------------------------------------------------------------------
#將hehe表的hehe_id列修改為varchar(255)類型
alter table hehe
modify hehe_id varchar(255);
#將hehe表的bbb列修改為int類型
alter table hehe
modify bbb int;
----------------------------------------------------------------------
#刪除指定的列
alter table hehe
drop column_name
#重新命名資料表
alter table hehe
rename to wawa;
----------------------------------------------------------------------
#將wawa表的欄位bbb欄位重新命名為ddd
alter table wawa
change bbb ddd int;
#刪除表
drop table 表名
----------------------------------------------------------------------
資料庫約束
not null
unique
primary key
foreign key
check
#not null約束



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.