0% found this document useful (0 votes)
39 views2 pages

PRG 2

The document outlines the creation and constraints of a SQL table named 'student_info' which includes fields for name, roll number, gender, age, and mobile number. It describes various successful and failed insert operations based on the defined constraints, such as name being uppercase, roll number being greater than zero, age not being null, and gender being limited to specific values. The final output shows the successful entries in the table, including one entry with a null mobile number.

Uploaded by

lifanmohammed77
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views2 pages

PRG 2

The document outlines the creation and constraints of a SQL table named 'student_info' which includes fields for name, roll number, gender, age, and mobile number. It describes various successful and failed insert operations based on the defined constraints, such as name being uppercase, roll number being greater than zero, age not being null, and gender being limited to specific values. The final output shows the successful entries in the table, including one entry with a null mobile number.

Uploaded by

lifanmohammed77
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

SQL> set linesize 150;

SQL> create table student_info(name varchar(15)not null check(name=upper(name)),


2 rollno number(10)not null check(rollno>0),
3 gender char(15)not null check(gender in('male','female','transgend')),
4 age number(10)not null,
5 mobile_no number(15)null);

Table created.

a,the student table must be in a capital letter

SQL> insert into student_info values('LIFAN',1001,'male',18,8973648822);

1 row created.

SQL> insert into student_info values('lifan',1001,'male',18,8973648822);


insert into student_info values('lifan',1001,'male',18,8973648822)
*
ERROR at line 1:
ORA-02290: check constraint (SYSTEM.SYS_C004034) violated

b,the roll number must be greater than zero

SQL> insert into student_info values('SHAHUL',1002,'male',35,8973648822);

1 row created.

SQL> insert into student_info values('SHAHUL',0,'male',35,8973648822);


insert into student_info values('SHAHUL',0,'male',35,8973648822)
*
ERROR at line 1:
ORA-02290: check constraint (SYSTEM.SYS_C004035) violated

c,the age cannot be a null value

SQL> insert into student_info values('RASOOL',1003,'female',28,8973648821);

1 row created.

SQL> insert into student_info values('RASOOL',1003,'female',null,8973648821);


insert into student_info values('RASOOL',1003,'female',null,8973648821)
*
ERROR at line 1:
ORA-01400: cannot insert NULL into ("SYSTEM"."STUDENT_INFO"."AGE")

d,the gender must be "MALE" or "FEMALE" or "TRANSGEND"

SQL> insert into student_info values('BEEVI',1004,'female',29,8973648831);

1 row created.

SQL> insert into student_info values('BEEVI',1004,'transmale',29,8973648831);


insert into student_info values('BEEVI',1004,'transmale',29,8973648831)
*
ERROR at line 1:
ORA-02290: check constraint (SYSTEM.SYS_C004036) violated
e,the mobile number may contain null value

SQL> insert into student_info values('MOHAMMED',1005,'male',39,8973648841);

1 row created.

SQL> insert into student_info values('MOHAMMED',1005,'male',39,null);

1 row created.

SQL> select*from student_info;

NAME ROLLNO GENDER AGE MOBILE_NO

--------------- ---------- --------------- ---------- ----------

LIFAN 1001 male 18 8973648822

SHAHUL 1002 male 35 8973648822

RASOOL 1003 female 28 8973648821

BEEVI 1004 female 29 8973648831

MOHAMMED 1005 male 39 8973648841

MOHAMMED 1005 male 39

6 rows selected.

SQL> spool off

You might also like