hi
周一是谁设定的。。。、
1、JS
主要是DOM的内容,本来是打算就随便看看,粘贴复制就算了的,但是看看后面还要学习iQuery等内容,还是好好看看吧,DOM这边总有些东西有点蛋疼。。。代码先不上了,待完成这一章的编程练习再说好了,吃饭去
------------------17:19-----------------------
2、MySQL
---约束---
--目的是为了保证数据的完整性和一致性
--分为表级约束和列级约束
--仅针对某一对象(一列),称为列级约束;若大于1列,就是表级
--五种约束:DEFAULT,NOT NULL,PRIMARY KEY,UNIQUE KEY,FOREIGN KEY
---FOREIGN KEY 外键约束---
--实现一对一或一对多
--使用该约束需要一些条件,比如父表和子表(默认存储引擎都为Inno DB),外键列和参照列(具有相似的数据类型),索引的创立(默认的主键或者自己创建)等
--实现以上要求,可以创建数据表之后,输入SHOW CREATE TABLE table_name;命令查看
--使用外键,如下所示
mysql> CREATE TABLE province(
-> id SMALLINT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
-> pename VARCHAR(20) NOT NULL);
Query OK, 0 rows affected (0.04 sec)
mysql> SHOW CREATE TABLE province;
+----------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+----------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| province | CREATE TABLE `province` (
`id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
`pename` varchar(20) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+----------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> CREATE TABLE users(
-> id SMALLINT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
-> username VARCHAR(10) NOT NULL,
-> pid BIGINT,
-> FOREIGN KEY(pid) REFERENCES province (id)
-> );
ERROR 1215 (HY000): Cannot add foreign key constraint
mysql> CREATE TABLE users(
-> id SMALLINT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
-> username VARCHAR(10) NOT NULL,
-> pid SMALLINT UNSIGNED,
-> FOREIGN KEY(pid) REFERENCES province (id)
-> );
Query OK, 0 rows affected (0.04 sec)
注意,这里体现出1】INNODB的检验;2】数据类型的相似条件;3】FOREIGN KEY的使用方式
另外,区分好子表users,父表province,外键列pid,参照列id
---外键约束的参照操作---
--CASCADE,SET NULL,RESTRICT,NO ACTION
--表示主表做变化后,子表是否变化
--需要注意的是,要想往子表中插入记录,必须先往父表中插入记录,不然你让子表去哪里参考
mysql> INSERT province(pename) VALUES('A');
Query OK, 1 row affected (0.01 sec)
mysql> INSERT province(pename) VALUES('B');
Query OK, 1 row affected (0.01 sec)
mysql> INSERT province(pename) VALUES('C');
Query OK, 1 row affected (0.01 sec)
mysql> INSERT users1(username,pid) VALUES('TOM',2);
Query OK, 1 row affected (0.01 sec)
mysql> INSERT users1(username,pid) VALUES('JACK',1);
Query OK, 1 row affected (0.01 sec)
mysql> SELECT * FROM users1;
+----+----------+------+
| id | username | pid |
+----+----------+------+
| 1 | TOM | 2 |
| 2 | JACK | 1 |
+----+----------+------+
2 rows in set (0.00 sec)
mysql> DELETE FROM province WHERE id=3;
Query OK, 1 row affected (0.01 sec)
mysql> SELECT * FROM users1;
+----+----------+------+
| id | username | pid |
+----+----------+------+
| 1 | TOM | 2 |
| 2 | JACK | 1 |
+----+----------+------+
2 rows in set (0.00 sec)
mysql> DELETE FROM province WHERE id=2;
Query OK, 1 row affected (0.01 sec)
mysql> SELECT * FROM users1;
+----+----------+------+
| id | username | pid |
+----+----------+------+
| 2 | JACK | 1 |
+----+----------+------+
1 row in set (0.00 sec)
--CASCADE-父子同步删除或更新
--SET NULL-父删除,则子为NULL;另外,子不能设置为NOT NULL
--RESTRICT-拒绝对父的删除和更新
--NO ACTION-类似上一个
--很多情况,多使用逻辑的外键约束,不适用这种innodb的物理约束
---表级和列级
--列级,在列的声明时或声明后定义,比如FOREIGN KEY
--表级,用的少,必须在列定义后声明
---修改数据表---
--即列的添加/删除,约束的添加/删除
--添加列
-ALTER TABLE tbl_name ADD [COLUMN] col_name column_definition [FIRST|AFTER col_name]
mysql> ALTER TABLE users1 ADD password VARCHAR(32) NOT NULL AFTER username;
Query OK, 0 rows affected (0.08 sec)
Records: 0 Duplicates: 0 Warnings: 0
-添加多列:ALTER TABLE tbl_name ADD [COLUMN](col_name column_definition,...)位置无法再选
--删除列
-ADD变为DROP