ºìÁªLinuxÃÅ»§
Linux°ïÖú

mysql ÖÐ ÊÓͼ ¸üР³ö´í £¡ Çó¾È

·¢²¼Ê±¼ä:2011-11-17 22:04:19À´Ô´:ºìÁª×÷Õß:linuxydy
ÕâÊÇÎÒµÄѧÉú±í
mysql> create table Student
(Sno char(9) primary key,
/*Áм¶ÍêÕûÐÔÔ¼Êø£¬SnoÊÇÖ÷¼ü,char(n) Êdz¤¶ÈΪnµÄ¶¨³¤×Ö·û´®,
varchar(n) ×î´ó³¤¶ÈΪnµÄ±ä³¤×Ö·û´®*/
Sname char(8) unique,/*Sname ȡΨһֵ*/
Ssex char(4),/*ÄлòÕßÅ® ¸÷Õ¼Á½¸ö×Ö½Ú*/
Sage smallint,
Sdept char(4));
mysql> describe Student;

ÕâÊÇÎÒ¶¨ÒåµÄÊÓͼ
create view IS_Student
as
select Sno,Sname,Sage
from Student
where Sdept='IS'
with check option;
ÎÒÒªÔÚÊÓͼÖвåÈëÒ»¸öÔª×é
mysql> insert
-> into IS_Student
-> values('200815129','³Â¾²','20');
Query OK, 1 row affected (0.00 sec)

mysql> select * from IS_Student;
+-----------+--------+------+
| Sno | Sname | Sage |
+-----------+--------+------+
| 200815126 | ÕÔÔÆ | 18 |
| 200815125 | ÕÅÁ¢ | 19 |
+-----------+--------+------+
2 rows in set (0.00 sec)


Õâ¸öʱºò ³ö´íÁË IS_Student ÊÓͼÖРûÓÐ ÎÒ²åÈëµÄÔª×é
¶østudent ±íÖÐ Ôò ÏÔʾ ÈçÏ Ôõô°ì°¡ ºÜ׿±°¡
mysql> select * from Student;
+-----------+--------+------+------+-------+
| Sno | Sname | Ssex | Sage | Sdept |
+-----------+--------+------+------+-------+
| 200815129 | ³Â¾² | NULL | 20 | NULL |
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 0 ÌõÆÀÂÛ