记录

pycharm连接mysql出错:

 

 

 

删除一行:delete from classcharger where id=1;

 

修改表记录:update student2 set charger_id=4 where id=8 or id=9 or id=14;

 创建主表:

CREATE TABLE classcharger(id tinyint PRIMARY KEY auto_increment,
name VARCHAR (20),age INT ,is_married boolean);
INSERT INTO classcharger(name,age,is_married)VALUES ('bingbing',12,0),('dandan',14,0),('waiwai',20,0),('shanshan',20,0),('xiaoyu',21,0);
创建子表:
CREATE TABLE student2(id INT PRIMARY KEY auto_increment,
name VARCHAR (20),
charger_id tinyint,FOREIGN KEY (charger_id) REFERENCES classcharger(id)
) engine=innodb;
INSERT INTO Student2(name,charger_id) VALUES ("alvin1",2),
("alvin2",2),
("alvin3",4),
("alvin4",3),
("alvin5",5),
("alvin6",3),
("alvin7",2);

-----------增加外键和删除外键---------

ALTER TABLE student  ADD CONSTRAINT abc
                     FOREIGN KEY(charger_id)
                     REFERENCES  classcharger(id);
ALTER TABLE student DROP FOREIGN KEY abc;

 

 

posted @ 2019-04-19 11:22  aggressive2019  阅读(124)  评论(0编辑  收藏  举报