程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> MySQL綜合教程 >> mysql基本總結

mysql基本總結

編輯:MySQL綜合教程

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約束



  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved