Beruflich Dokumente
Kultur Dokumente
2911190
EX.NO:-2 DATE:-
Aim: To Perform the DDL Commands Q1: Create a table called Employee with the following structure
Name Fname Minit Lname SSN Gender Salary SuperSSN Dno Allow Null for all columns except Fname Set primary constraint to SSN Type varchar2(10) varchar2(1) varchar2(10) number(9) varchar2(21) number(9,2) number(9) number(1)
Table created. SQL> desc employee Name Null? ----------------------------------------- ---------------FNAME NOT NULL MINIT LNAME SSN NOT NULL GENDER SALARY SUPERSSN DNUMBER Type -------------------VARCHAR2(10) VARCHAR2(11) VARCHAR2(10) NUMBER(9) VARCHAR2(6) NUMBER(9,2) NUMBER(9) NUMBER(13)
SUJIT KUMAR
2911190
Table created. SQL> desc Department; Name Null? ----------------------------------------- ---------------DNAME NOT NULL DNUMBER NOT NULL MGRSSN MGRSTARTDATE Type -------------------VARCHAR2(6) NUMBER(1) NUMBER(9) DATE
Q3: Create a table called Dept_locations with the following structure Name Type
Dnumber number(1) Dlocation varchar2(10) Allow Not Null for all columns Set primary key constraint to both Dnumber and Dlocation Set foriegn key constraint to Dnumber SQL>Create table Dept_Locations(Dnumber Number(1), DLocation VarChar2(10),
Primary Key (Dnumber, DLocation),Constraint fk2 Foreign Key (Dnumber) references Department(DNumber));
Table created.
SUJIT KUMAR
2911190
SQL> desc Dept_locations; Name Null? ----------------------------------------- ---------------DNUMBER NOT NULL DLOCATION NOT NULL Type -------------------NUMBER(1) VARCHAR2(10)
Table created. SQL> desc Project; Name Null? ----------------------------------------- ---------------PNAME PNUMBER NOT NULL DNUM Type -------------------VARCHAR2(15) NUMBER(2) NUMBER(1)
SUJIT KUMAR
2911190
Table created. SQL> desc Works_on; Name Null? ----------------------------------------- ---------------ESSN NOT NULL PNO NOT NULL HOURS Type -------------------NUMBER(9) NUMBER(2) NUMBER(2,1)
Table created.
SUJIT KUMAR
2911190
SQL> desc dependent Name Null? ----------------------------------------- ----------------ESSN NOT NULL DEPENDENT_NAME NOT NULL GENDER BDATE RELATIONSHIP Type ------------------NUMBER(10) VARCHAR2(10) VARCHAR2(10) DATE VARCHAR2(10)
Q7: Add a column Bdate to the employee table of data type Date with null allowed
SQL>alter table employee add(bdate date); Table altered.
SQL> desc employee Name Null? ----------------------------------------- ----------------FNAME NOT NULL MINIT LNAME SSN NOT NULL GENDER SALARY SUPERSSN DNUMBER BDATE Type ------------------VARCHAR2(10) VARCHAR2(11) VARCHAR2(10) NUMBER(9) VARCHAR2(6) NUMBER(9,2) NUMBER(9) NUMBER(13) DATE
Q8: Modify the column width of the relationship field of Dependent table
SQL>alter table dependent modify(relationship varchar2(35)); Table altered.
SUJIT KUMAR
2911190
SQL> desc dependent Name Null? Type ----------------------------------------- ---------------- -------------------ESSN NOT NULL NUMBER(10) DEPENDENT_NAME NOT NULL VARCHAR2(10) GENDER VARCHAR2(10) BDATE DATE RELATIONSHIP VARCHAR2(35)
Q9: Add constraints to the employee table that Dno as the foreign key
SQL>alter table employee add(constraint f10 foreign key(dnumber) references
depatment(dnumber));
Table altered. SQL> desc employee Name Null? ----------------------------------------- ---------------FNAME NOT NULL MINIT LNAME SSN NOT NULL GENDER SALARY SUPERSSN DNUMBER BDATE Type -------------------VARCHAR2(10) VARCHAR2(11) VARCHAR2(10) NUMBER(9) VARCHAR2(6) NUMBER(9,2) NUMBER(9) NUMBER(13) DATE
Q10: Add constraints to the employee table that SuperSSN as the foreign key
SQL>alter table employee add(constraints jk foreign key(superssn) references
project(pnumber));
SUJIT KUMAR
2911190
Name Null? ----------------------------------------- ---------------FNAME NOT NULL MINIT LNAME SSN NOT NULL GENDER SALARY SUPERSSN DNUMBER BDATE
Type -------------------VARCHAR2(10) VARCHAR2(11) VARCHAR2(10) NUMBER(9) VARCHAR2(6) NUMBER(9,2) NUMBER(9) NUMBER(13) DATE
Q11: Add constraints to the employee table to check the SSN while entering (i.e)
empno>100 SQL> alter table employee add check(ssn>100); Table altered. SQL> desc employee Name Null? ----------------------------------------- ---------------FNAME NOT NULL MINIT LNAME SSN NOT NULL GENDER SALARY SUPERSSN DNUMBER BDATE Type -------------------VARCHAR2(10) VARCHAR2(11) VARCHAR2(10) NUMBER(9) VARCHAR2(6) NUMBER(9,2) NUMBER(9) NUMBER(13) DATE
Table altered.
SUJIT KUMAR
2911190
SQL> desc employee Name Null? ----------------------------------------- ---------------FNAME NOT NULL MINIT LNAME SSN NOT NULL GENDER SALARY SUPERSSN DNUMBER BDATE Type -------------------VARCHAR2(10) VARCHAR2(11) VARCHAR2(10) NUMBER(9) VARCHAR2(6) NUMBER(9,2) NUMBER(9) NUMBER(13) DATE
SUJIT KUMAR
2911190
Result:
The queries in Data Definition Language that is DDL are done successfully and the output is verified.