##MySql数据库表的操作与应用
#新建数据库
CREATE DATABASE school;
#查看数据库
SHOW DATABASES;
#查看当前新建数据库
SHOW CREATE DATABASE school;
#换库
USE school;
#删除新建的库
DROP DATABASE school;
#查询当前所在的数据库
SELECT DATABASE();
#新建数据库表
CREATE TABLE student(
#设置主键,同时设置自动增长
sID INT PRIMARY KEY AUTO_INCREMENT,
studentName VARCHAR(10),
phone VARCHAR(20),
address VARCHAR(200)
);
#添加数据
INSERT INTO student(studentName,phone,address) VALUES('郭子豪','17744673401','黄河路13号'),
('李振烨','15638431234','花园路15号'),
('陈富国','12345676543','东风路12号');
#查询表结构
DESC student;
#查询数据表内容
SELECT * FROM student;
#修改数据表
UPDATE student SET studentname='张凡'WHERE sID=1;
UPDATE student SET address='中国'WHERE address='东风路12号';
UPDATE student SET phone='10086';
#删除数据表
DELETE FROM student WHERE sid=3;
DELETE FROM student;
#删除表
TRUNCATE TABLE student;
#删除主键约束
INSERT INTO student VALUES(NULL,'郭子豪','12345678','俄罗斯');
INSERT INTO student VALUES('郭子豪','12306','俄罗斯');
UPDATE student SET phone='12306'WHERE sid=4;
ALTER TABLE student DROP PRIMARY KEY;
#修改约束
ALTER TABLE student MODIFY sid INT;
#显示表结构
DESC student;
#添加主键 自动增长
ALTER TABLE student ADD PRIMARY KEY(sid);