msyql命令大全

1.创建数据库

create database samp_db character set gbk;

2.创建数据库

create table students
(
id int unsigned not null auto_increment primary key,
name char(30) not null,
sex char(4) not null,
age tinyint unsigned not null,
tel char(13) null default "-"
);

"id" 为列的名称;
"int" 指定该列的类型为 int(取值范围为 -8388608到8388607), 在后面我们又用 "unsigned" 加以修
饰, 表示该类型为无符号型, 此时该列的取值范围为 0到16777215;
"not null" 说明该列的值不能为空, 必须要填, 如果不指定该属性, 默认可为空;
"auto_increment" 需在整数列中使用, 其作用是在插入数据时若该列为 NULL, MySQL将自动产生一个比
现存值更大的唯一标识符值。在每张表中仅能有一个这样的值且所在列必须为索引列。
"primary key" 表示该列是表的主键, 本列的值必须唯一, MySQL将自动索引该列。

3.查询表中数据

select * from students where sex="女"

4.向表中插入数据


5.更新表中数据

update students set tel=default where id=5;(default为默认格式)

将所有人的年龄增加1: update students set age=age+1;

6.删除表中数据

删除id为2的行: delete from students where id=2;
删除表中的所有数据: delete from students;

7.在表中增加列

在表的最后追加列 address: alter table students add address char(60);
在名为 age 的列后插入列 birthday: alter table students add birthday date after age;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章