self_example/SQL_example/DML.sql

44 lines
1.1 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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大于230
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)
)