--创建数据库
CREATE DATABASE DAY01_TEST01_MARKET;
--创建表
CREATE TABLE CUSTOMERS(
C_NUM INT(11),
C_NAME VARCHAR(50),
C_CONTACT VARCHAR(50),
C_CITY VARCHAR(50),
C_BIRTH DATE
);
SELECT * FROM CUSTOMERS;
--移动字段
ALTER TABLE CUSTOMERS MODIFY C_CONTACT VARCHAR(50) AFTER C_BIRTH;
--将C_NAME字段数据类型修改
ALTER TABLE CUSTOMERS MODIFY C_NAME VARCHAR(70) ;
--将C_CONTACT字段改名为C_PHONE
ALTER TABLE CUSTOMERS CHANGE C_CONTACT C_PHONE VARCHAR(50);
--增加C_GENDER字段到C_NAME后面,数据类型
ALTER TABLE CUSTOMERS ADD COLUMN C_GENDER CHAR(1) AFTER C_NAME;
--将表名改为CUSTOMERS_INFO
ALTER TABLE CUSTOMERS RENAME CUSTOMERS_INFO;
--删除字段C_CITY
ALTER TABLE CUSTOMERS DROP C_CITY;
--创建数据库
CREATE DATABASE DAY01_TEST02_COMPANY;
--创建表
CREATE TABLE EMPLOYEES(
EMPNUM INT(11),
LASTNAME VARCHAR(50),
FIRSTNAME VARCHAR(50),
MOBILE VARCHAR(25),
CODE INT,
JOBTITLE VARCHAR(50),
BIRTH DATE
);
--将表EMPLOYEES的BIRTH字段改名为BIRTHDAY
ALTER TABLE EMPLOYEES CHANGE BIRTH BIRTHDAY DATE;
--修改CODE字段,数据类型为CHAR(1)
ALTER TABLE EMPLOYEES MODIFY CODE VARCHAR(70);
--删除字段JOBTITLE
ALTER TABLE EMPLOYEES DROP JOBTITLE;
--增加字段名FAVORIATE_ACTIVITY,数据类型为VARCHAR(100)
ALTER TABLE EMPLOYEES ADD COLUMN FAVORIATE_ACTIVITY CHAR(100);
--将表EMPLOYEES的名称修改为 EMPLOYEES_INFO
ALTER TABLE EMPLOYEES RENAME EMPLOYEES_INFO;
SELECT * FROM EMPLOYEES;
--将EMPNUM设置为主键,并自动增长
ALTER TABLE EMPLOYEES MODIFY EMPNUM INT(11) PRIMARY KEY AUTO_INCREMENT;