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.

解决方案 »

  1.   

    1. Values for the staffid attribute should be a string of exactly 4 characters, and should start with
    letter ‘s’.in other database, you can use the CHECK to enforce the data comply with the rule, but MySQL does not support CHECK ! in MySQL it can be done in the Trigger
    2. Values for the sid attribute of the Student relation should be a string of exactly 4 characters, and
    should start with letter ‘u’.same like Question 1

    3. Values for the title attribute should be one of the following strings: “Lecturer”, “Senior
    Lecturer”, “Associate Professor” and “Professor”.in MySQL, you can use the ENUM , for example 
    CREATE TABLE sizes (
        name ENUM('small', 'medium', 'large')
    );

    4. Values for the credits attribute should be integers between 0 and 6.same like Question 1

    5. Values for the sex attribute should be either ‘M’ (for male) or ‘F’ (for female). NULL values are not
    allowed.same like question 3

    CREATE TABLE sizes (
        sex ENUM('small', 'medium', 'large') not null
    );
      

  2.   

    第五个的写法是不是alter table Student
    add constraint CK_Student check (sex IN(‘M','F')) 
      

  3.   

    我用的是postgresql  postgresql 应该可以用check吧
      

  4.   

    有没有人可以推荐一些postgresql 的 网站可以让我学习一下
      

  5.   


    PostgreSQL 8.1 中文文档
      

  6.   

    http://www.pgsqldb.orggoogle 一下很多