mysql -uroot -pshengri20020423
create database library;
use library
CREATE TABLE subscribe (
id INT AUTO_INCREMENT PRIMARY KEY,
email VARCHAR(255) NOT NULL,
status TINYINT NOT NULL DEFAULT 0,
code VARCHAR(10)
);
INSERT INTO subscribe (email, status, code) VALUES
('[email protected]', 1, 'abc123'),
('[email protected]', 0, 'def456'),
('[email protected]', 1, 'ghi789'),
('[email protected]', 0, 'jkl012'),
('[email protected]', 1, 'mno345');
查看表中数据:
SELECT * FROM subscribe;
SELECT email, status FROM subscribe;
DELETE FROM subscribe WHERE email = '[email protected]';
实验三
create database StudentInfo
use StudentInfo
CREATE TABLE Student (
num INT(10) PRIMARY KEY COMMENT '学号',
name VARCHAR(20) NOT NULL COMMENT '姓名',
sex VARCHAR(4) NOT NULL COMMENT '性别',
birthday DATETIME COMMENT '出生日期',
address VARCHAR(50) COMMENT '家庭住址'
);
CREATE TABLE grade (
id INT(10) PRIMARY KEY COMMENT '编号',
Course VARCHAR(10) NOT NULL COMMENT '课程名',
S_num INT(10) NOT NULL COMMENT '学号',
grade VARCHAR(4) COMMENT '成绩'
);
ALTER TABLE grade MODIFY Course VARCHAR(20);
ALTER TABLE grade MODIFY Course varchar(20) AFTER s_num;
ALTER TABLE grade CHANGE grade score VARCHAR(4);
ALTER TABLE grade ENGINE=MyISAM;
RENAME TABLE grade TO gradeInfo;
student
ALTER TABLE student DROP COLUMN address;
ALTER TABLE student ADD phone VARCHAR(15);
DROP TABLE student;
ALTER TABLE table_name
MODIFY column_name new_data_type [constraints];
ALTER TABLE table_name
MODIFY column_name new_data_type [constraints] AFTER column_to_place_after;
创建一个表实验三
create table if not exists user(
id int primary key auto_increment comment '编号',
username varchar(20) unique comment '用户名',
phonenum char(11) not null comment '手机号码',
gender enum('男','女','保密') comment '性别',
rtime datetime not null comment '注册时间',
grade int check (grade >=0 and grade <= 100) comment '会员等级'
);