搜题
问题   更新时间2023/7/3 22:20:00

4.数据库company中有如下两张表
表offices(office_code, city, address, country, postal_code)office_code为主键,
表employees(employee_number, name, mobile, office_code, job_title, note, gender),employee_number为主键且自增.
(1)创建数据库company,写出创建语句; (2分)


(2)创建表offices和employees,写出创建语句;(8分)











(3)将表employees的mobile字段修改到office_code字段后面;(3分)


(4)修改表employees的gender字段,数据类型为CHAR(1),非空约束;(3分)


(5)给表employees增加字段名favoriate_activity,数据类型为VARCHAR(100);(4分)

(1)创建数据库company,写出创建语句; (2分) 答案: CREATE DATABASE company; (2)创建表offices和employees,写出创建语句;(8分) 答案: CREATE TABLE offices( Office_code int(10) not null, city varchar(50), address varchar(50), country varchar(50), postal_code varchar(15) PRIMARY KEY (office_code) ); CREATE TABLE employees( Employee_number INT(10) NOT NULL PRIMARY KEY AUTO_INCREMENT, name VARCHAR(50), mobile VARCHAR(25), office_code INT(10), job_title VARCHAR(50), note VARCHAR(255), gender VARCHAR(5), ); (3)将表employees的mobile字段修改到office_code字段后面;(3分) 答案: ALTER TABLE employees MODIFY mobile VARCHAR(25) AFTER office_code; (4)修改表employees的gender字段,数据类型为CHAR(1),非空约束;(3分) 答案: ALTER TABLE employees MODIFY gender CHAR(1) NOT NULL; (5)给表employees增加字段名favoriate_activity,数据类型为VARCHAR(100);(4分) 答案: ALTER TABLE employees ADD favoriate_activity VARCHAR(100);
王老师:19139051760(拨打)