USE db2;
CREATE TABLE stu4(
sid INT PRIMARY KEY AUTO_INCREMENT,
sname VARCHAR(1000),
age INT,
address VARCHAR(1000),
FOREIGN KEY(sname)REFERENCES student(createtime));

INSERT INTO stu1 VALUES(NULL,'张无忌',25,'光明顶'),(NULL,'赵敏',30,'光明顶1'),(NULL,'周芷若',40,'光明顶2');
#修改张无忌的地址
UPDATE stu1 SET address='嵩山' WHERE sname='张无忌';
#修改周芷若的年龄和地址
UPDATE stu1 SET address='峨眉',age=50 WHERE sname='周芷若';

#####mysql中的简单查询
#查询stu表中的所有记录
SELECT sid,sname,age,address FROM stu1;
SELECT * FROM stu1;
#查阅所有sid和sname,别名as
SELECT sid AS id,sname AS `name` FROM stu1;
#查询名字是张无忌的
SELECT * FROM stu1 WHERE sname='张无忌';
#查询sid大于2，且年龄大于30的
SELECT * FROM stu1 WHERE sid>=1 AND age>30


### 创建部门表
CREATE TABLE dept (
  did INT PRIMARY KEY,
  dname VARCHAR(100)
)

### 创建员工表
CREATE TABLE emp (
  eid INT PRIMARY KEY,
  ename VARCHAR(100),
  age INT,
  edid INT,
  FOREIGN KEY(edid) REFERENCES dept(did) 
)



