CONSTRAINTS
1. Values for the staffid attribute should be a string of exactly 4 characters, and should start with
letter ‘s’.
2. Values for the sid attribute of the Student relation should be a string of exactly 4 characters, and
should start with letter ‘u’.
3. Values for the title attribute should be one of the following strings: “Lecturer”, “Senior
Lecturer”, “Associate Professor” and “Professor”.
4. Values for the credits attribute should be integers between 0 and 6.
5. Values for the sex attribute should be either ‘M’ (for male) or ‘F’ (for female). NULL values are not
allowed.
还是上次的 几个题目
我之后看了postgresql 的 document 和Google 了一下
我想这几个constraint 是可以用create domain 来完成
请问 mysql 里面有没有 create domain这种
如果这些题目是放在mysql里面写 应该是如何写
1. Values for the staffid attribute should be a string of exactly 4 characters, and should start with
letter ‘s’.
2. Values for the sid attribute of the Student relation should be a string of exactly 4 characters, and
should start with letter ‘u’.
3. Values for the title attribute should be one of the following strings: “Lecturer”, “Senior
Lecturer”, “Associate Professor” and “Professor”.
4. Values for the credits attribute should be integers between 0 and 6.
5. Values for the sex attribute should be either ‘M’ (for male) or ‘F’ (for female). NULL values are not
allowed.
还是上次的 几个题目
我之后看了postgresql 的 document 和Google 了一下
我想这几个constraint 是可以用create domain 来完成
请问 mysql 里面有没有 create domain这种
如果这些题目是放在mysql里面写 应该是如何写
ALTER TABLE products ADD CONSTRAINT some_name UNIQUE (product_no);我想问 第一句是 在已经insert 了 data之后才有作用的吗?
Query OK, 0 rows affected (0.08 sec)mysql> desc c;
+-------+------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+------------+------+-----+---------+-------+
| name | varchar(4) | YES | | NULL | |
+-------+------------+------+-----+---------+-------+
1 row in set (0.01 sec)mysql> insert into c values("asfd");
Query OK, 1 row affected (0.03 sec)mysql> select * from c;
+------+
| name |
+------+
| asfd |
+------+
1 row in set (0.00 sec)
mysql的check好像不好用啊
==我再看看
1.
至于你的验证可以在服务端验证插到表中都是以's'打头的数据
2.
也可以都插入
然后在执行删除
mysql> select * from c;
+------+
| name |
+------+
| asfd |
| asfd |
+------+
2 rows in set (0.00 sec)mysql> delete from c where left(name,1)="a";
Query OK, 2 rows affected (0.01 sec)mysql> select * from c;
Empty set (0.00 sec)
The CHECK clause is parsed but ignored by all storage engines.
如果一定要在MYSQL数据库中实现,则可以使用触发器来检查。