DBMS
----
Theory qns
----------
1. Database and its need
2. Relational Data Model
3. Relation, domain
4. Attribute
5. Tuple
6. Degree
7. Cardinlaity
8. Primary key, Candidate key, alternate key,foreign key
9. SQL
10. DDL
11. DML
12. DISTINCT
13. AS(aliasing)
14. IS,IN,LIKE,BETWEEN-AND
15. diff b/w alter(ddl) and update(dml)
16. diff b/w delete(dml) and drop(ddl) ddl commands can't rollback, it is
automatically committed. but dml commands can rollback
17. joins (cross,equi,natural)
18. order by and group by
19. where and having
20. aggregate functions (sum, avg,min,max,count)
21. functions that work only on numeric type -----sum,avg
22. functions that work on all data type--min,max,count
23. char and varchar
24. table constraint(not null,unique,primary key)
SQL Commands
--------------
1. create table table-name(colname datatype[(size)] [constraint-name], colname
datatype[(size)] [constraintname],................);
char/varchar----need size
datatype-----------int(integer),char,varchar,float,date
char[(n)]
varchar(n)
2. insert into table-name[(colnames)] values(value1,value2,..........)
student(rno,name,grade,section)
insert into student values(1,'abc',12,'K');
insert into student(rno,section) values(2,'J');
3. select */col-list from table-name(s) [where condition] [order by col-name
asc/desc] [group by col-name] [having condition];
condition: relational operators, logical operators, is,in, between-and,like
(wildcard characters : % and _)
4. update table-name set col-name=new-value[,col-name=new-value,.............]
[where condition];
update emp set sal=sal+100;
update emp set sal=sal+100,comm=comm+50;
update emp set comm=null where empno=7540;
5. delete from table-name [where condition];
6. alter table
* to add a column
* modify the existing column datatype and size
* delete columns
* add primary key constraint
* drop primary key constraint
student(name,grade,section)
alter table student add(mark int); #student(name,grade,section,mark)
alter table student modify name varchar(25);
alter table student drop grade;
alter table student drop grade,drop section;
#student(rno,name,grade,section)
alter table student add primary key(rno);
#student(name,grade,section)
alter table student add(rno int primary key);
7. create database databasename;
8. use databasename;
9. show databases;
10. show tables;
11. desc table-name; or describe table-name;
12. drop database databasename;
13. drop table table-name;
joins
------
Table T1(rno,name,grade), Table T2(rno,mark)
cross join: degree : sum of the degree of two relations, cardinality : product of
cardinality of two relations
select * from t1,t2;
or
select * from t1 cross join t2;
or
select * from t1 join t2;
equi join:
select * from t1,t2 where t1.rno=t2.rno;
natural join
select * from t1 natural join t2;