Constraint in SQL
Constraint:
- Primary Key
- Not Null
- Check and
- References.
Creating Table using primary key and not null
create table student
(
rollno number primary key,
name varchar2(15) not null,
Branch varchar2(5),
gender varchar2(7),
DOB date,
email_id varchar2(25),
Address varchar2(25),
phone_no number
);
Creating Table using check and References
create table student_marks
(
rollno number references students_035,
marks number
constraint check_marks check(marks between 0 and 100)
);
We apply the check Constraint on marks so if marks is not between the 0 and 100 then sql command is violated.
Example:
SQL> insert into student_marks values(1,67);
1 row created.
SQL> insert into student_marks values(40,107);
insert into student_marks values(40,107)
*
ERROR at line 1:
ORA-02290: check constraint (SCOTT.CHECK_MARKS) violated
Note: All commands are apply on above two tables for better understanding male your own table and attributes.
Query and any doubts please leave in comments.
Creating table in sql.
Create Table in Sql/oracle.
create table student
(
rollno number,
name varchar(30),
address varchar(30),
branch varchar(5),
phone no
):
"create table" is keyword use to define the table name and student is name of table
roll no , name etc are the attributes and number varchar are their data type.
Subscribe to:
Posts (Atom)
Powered by Blogger.
Popular Posts
-
Click Below to get Sanjay Sharma PDF file https://drive.google.com/open?id=0BxDBNrqmA87UNklZbl9xYTBjclk
-
You can control the media player via your smartphone. Follow these steps and you are good to go. 1.Download and install GOM media playe...
-
Theo Jansen was born in 1948, Scheveningen in the Netherlands. Theo Jansen grew up with knack for both physics and art and goes to study ...
-
Bored of being sitting in front of your desktop (pc/laptop) for hours to work , relax and give control of your desktop to your smartphone. ...
-
paper mache can be used to prepare decorative items for home... It is an easiest and cheapest way to prepare the items for decoration. Her...