首页
Web开发
Windows程序
编程语言
数据库
移动开发
系统相关
微信
其他好文
会员
首页
>
数据库
> 详细
mysql基本总结
时间:
2014-10-22 14:42:51
阅读:
320
评论:
0
收藏:
0
[点我收藏+]
标签:
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基本总结
标签:
mysql基础
原文地址:http://blog.csdn.net/hephec/article/details/40374339
踩
(
0
)
赞
(
0
)
举报
评论
一句话评论(
0
)
登录后才能评论!
分享档案
更多>
2021年07月29日 (22)
2021年07月28日 (40)
2021年07月27日 (32)
2021年07月26日 (79)
2021年07月23日 (29)
2021年07月22日 (30)
2021年07月21日 (42)
2021年07月20日 (16)
2021年07月19日 (90)
2021年07月16日 (35)
周排行
更多
数据库进阶
2021-07-29
在 Oracle 数据库中执行 SQL 语句遇到特殊字符的转义方式
2021-07-28
Windows Logstash同步 Sqlserver 到Elasticsearch
2021-07-26
mysql数据库(11):恢复数据
2021-07-26
mysql数据库(9):常用查询的例子
2021-07-26
SQLAlchemy 多对多
2021-07-26
ClickHouse的JDBC连接
2021-07-26
Apache HBase 1.7.1 发布,分布式数据库
2021-07-26
数据库常用架构和同步工作原理
2021-07-26
MySQL数据库设计规范(仅供参考)
2021-07-26
友情链接
兰亭集智
国之画
百度统计
站长统计
阿里云
chrome插件
新版天听网
关于我们
-
联系我们
-
留言反馈
© 2014
mamicode.com
版权所有 联系我们:gaon5@hotmail.com
迷上了代码!