0% found this document useful (0 votes)
1 views13 pages

DBMS - DML - Select

The document discusses SQL constraints applied to a 'student' table, including primary keys, unique constraints, and check constraints. It provides examples of SQL commands for altering the table structure and querying data based on various conditions. Additionally, it covers selection queries to retrieve specific data from the student table, such as distinct marks and aggregate functions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views13 pages

DBMS - DML - Select

The document discusses SQL constraints applied to a 'student' table, including primary keys, unique constraints, and check constraints. It provides examples of SQL commands for altering the table structure and querying data based on various conditions. Additionally, it covers selection queries to retrieve specific data from the student table, such as distinct marks and aggregate functions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 13

Unit - II

Structured Query
Language
SQL Constraints
Recap

SQL> desc student;

Name Null? Type


----------------------------------------- -------- ----------------------------
REGNO VARCHAR2(20)
NAME VARCHAR2(20)
DOB DATE
MARK NUMBER(3)
Student Table Constraints
 SQL> select constraint_name,constraint_type from user_constraints
where table_name='STUDENT';

 no rows selected

 SQL> alter table student add constraint pk1 primary


key(regno);
 alter table student add primary key(regno);
 alter table student add primary key(regno,name);

 Table altered.
 SQL> select constraint_name,constraint_type from user_constraints
where table_name='STUDENT';
 CONSTRAINT_NAME C
 ------------------------------ -
 PK1 P
Student Table Constraints

 SQL> alter table student add constraint uk1 unique(name);

 Table altered.

 SQL> alter table student add constraint ck1 check( mark > 0 and
Mark <100);

 Table altered.
Student Table Constraints

 SQL> alter table student modify(dob date not null);

 Table altered.

 SQL> alter table student modify(mark number(3) default 0);

 Table altered.
Student Table Constraints
select

 Select * from student where marks in (10,20,30);


 Select * from student where marks marks=10 or marks=20 or
marks=30;

 Select * from student where branch = ‘CSE’ and marks in


(10,20,30);

 Select * from student where marks between 50 and 70;


select

 Select * from student where name = ‘a’;

 Select * from student where name like ‘a%’;

 Select * from student where name like ‘%a’;

 Select * from student where name like ‘%a%’;


select

 Select distinct marks from student;

 Select marks+10 as newmarks from student;

 Select * from student order by marks desc;


select

 Select count(*) from student;

 Select count(name) from student;

 Select min(marks) from student;


 max,avg,sum
 Constraints
 select

You might also like