使用database:
mysql> use mydata;
Datadase changed
创建表:
mysql> create table dept
(
depeno int primary key,
dname varchar(14),
loc varchar(13)
);
创建表
create table emp2
(
empno int primary key,
ename varchar(10),
job varchar(10),
mgr int,
hiredate datetime,
sal double,
comm double,
deptno int,
foreign key (deptno) references dept(deptno)
);
执行mysql的脚本文件
\.c:\\mysql_scrpt\\mydata.sql
敲?查询mysql常用的语法
mysql> show databases;
能看到有多少个databases
mysql> show tables;
能看见有多少个table
select * from
表里有多少数据
mysql> desc dept;
观察这个表的结构
mysql> insert into dept values (10,'A','A');
ERROR 1062
mysel> insert into dept values (20,'b','b');
mysql> commit;
执行一下提交
mysql> select * from dept order by deptno desc limit 3,3;
把数据选出来
从第3条往后数3条
dept为表名
mysql> delete from article;
删除表下面的数据(article为表名)
mysql> drop table article;
删除表(article为表名)
mysql> create table article
(
id int primary key auto_increment,
title varchar(255)
);
创建表 article
atuo_increment,自动递增
mysql> insert into article values (null,'a');
往article这张表里插数据
mysql> select * from article;
显示表里面的数据
mysql>create table article2
(
id int primary key,
title varchar(255)
);
创建表
mysql> insert into article (title) values ('c');
只插标题这个元素的数据
mysql> select now();
选取当前时间
mysq> select date_format(now(),'%Y-%m-%d %H:%i:%s');
把日期转为字符串
mysql> desc emp;
emp的格式
mysql> insert into emp values (9,'test','clerk',7369,'2015-1-20 13:23:45',8000,30,10);
往表里插数据
mysql> insert into emp values (10,'longmao','chifan',99,'2010-11-1 20:23:23',900,90,9);
mysql> use mydata;
Datadase changed
创建表:
mysql> create table dept
(
depeno int primary key,
dname varchar(14),
loc varchar(13)
);
创建表
create table emp2
(
empno int primary key,
ename varchar(10),
job varchar(10),
mgr int,
hiredate datetime,
sal double,
comm double,
deptno int,
foreign key (deptno) references dept(deptno)
);
执行mysql的脚本文件
\.c:\\mysql_scrpt\\mydata.sql
敲?查询mysql常用的语法
mysql> show databases;
能看到有多少个databases
mysql> show tables;
能看见有多少个table
select * from
表里有多少数据
mysql> desc dept;
观察这个表的结构
mysql> insert into dept values (10,'A','A');
ERROR 1062
mysel> insert into dept values (20,'b','b');
mysql> commit;
执行一下提交
mysql> select * from dept order by deptno desc limit 3,3;
把数据选出来
从第3条往后数3条
dept为表名
mysql> delete from article;
删除表下面的数据(article为表名)
mysql> drop table article;
删除表(article为表名)
mysql> create table article
(
id int primary key auto_increment,
title varchar(255)
);
创建表 article
atuo_increment,自动递增
mysql> insert into article values (null,'a');
往article这张表里插数据
mysql> select * from article;
显示表里面的数据
mysql>create table article2
(
id int primary key,
title varchar(255)
);
创建表
mysql> insert into article (title) values ('c');
只插标题这个元素的数据
mysql> select now();
选取当前时间
mysq> select date_format(now(),'%Y-%m-%d %H:%i:%s');
把日期转为字符串
mysql> desc emp;
emp的格式
mysql> insert into emp values (9,'test','clerk',7369,'2015-1-20 13:23:45',8000,30,10);
往表里插数据
mysql> insert into emp values (10,'longmao','chifan',99,'2010-11-1 20:23:23',900,90,9);
1452错误
mysql> alter table longmao add name varchar(255) after id;
往表里添加字段
mysql> insert into longmao values (3,'bb3');
同时往longmao 里插入id 和name
mysql> alter table longmao drop name;
删除longmao表里的name字段
mysql>update longmao set name='baobao' where id='1';
把id为1,name为null的name改成baobao