
create table 表名
(
sex char(2) check(sex='男' or sex='女') not null
)
默认性别为男的代码如下:
create table 学生表
(
学号 char(5) not null primary key,
姓名 varchar(10) not null,
性别 char(2) default '男' check (性别 in ('男','女')) //其中default '男' 就是默认性别为男。
)
扩展资料:
使用其他方法限制性别只能写男或女:
ALTER TALBE [表名]
ADD CONSTRAINT 约束名 CHECK(列名 in ('男', '女')) not null
注意:CHECK 约束可以应用于一个或者多个列,也可以将多个CHECK 约束应用于一个列。
当除去某个表时,对这个表的CHECK 约束也将同时被去除。
参考资料:百度百科-check约束
显示的时候<%%>里面if ele一下就行了,或者直接批量的用sql的update把数据改成男和女;update table set userSex='男' where userSex=0
update table set userSex='女' where userSex=1
c标签:
<c:if test="${employee.userSex==1 }">
<td>男</td>
</c:if>
<c:if test="${employee.userSex==0 }">
<td>女</td>
</c:if>
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)