SQL基础DDL语句

xiaoxiao2021-02-28  38

1,创建数据库test1

create database test1;

2,选择数据库test1

use test 1

3,查看test1数据库中创建的所有数据表

show tables;

4,删除test1数据库

drop database test1;

5,创建一个名称为 emp 的表。表中包括 3 个字段,ename(姓名),hiredate(雇用日期)、 sal(薪水),字段类型分别为 varchar(10)、date、int(2)

create table emp( ename varchar(10), hiredate date, sal decimal(10,2), deptno int(2) );

6,查看emp表的定义

desc emp;

7,查看创建表的sql语句

show create table emp;

8,删除数据库emp表

dorp table emp;

9,修改表emp的ename字段定义,将varchar(10)改为varchar(20)

alter table emp modify eanme varchar(20)

10, 表 emp 上新增加字段 age,类型为 int(3)

alter table emp add column age int(3);

11, 将字段age删除掉

alter table emp drop column age;

12, 将 age 改名为 age1,同时修改字段类型为 int(4)

alter table emp change age age1 int(4);

13,将新增的字段 birth date 加在 ename 之后:

alter table emp add birth date after ename;

14, 修改字段 age,将它放在最前面:

alter table emp modify age int(3) first;

转载请注明原文地址: https://www.6miu.com/read-2630575.html

最新回复(0)