0% found this document useful (0 votes)
9 views6 pages

DBMSPRAC

The document outlines various SQL commands including DDL (Data Definition Language) and DML (Data Manipulation Language) operations for creating and managing database tables. It covers creating tables with integrity constraints, performing joins (inner, outer), and manipulating strings using SQL operators. Additionally, it demonstrates the creation and modification of views in a database context.

Uploaded by

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

DBMSPRAC

The document outlines various SQL commands including DDL (Data Definition Language) and DML (Data Manipulation Language) operations for creating and managing database tables. It covers creating tables with integrity constraints, performing joins (inner, outer), and manipulating strings using SQL operators. Additionally, it demonstrates the creation and modification of views in a database context.

Uploaded by

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

DDL COMMANDS:

CREATE TABLE student(

name char(10),

rollno char(10),

marks char(5)

);

Alter table student Add(

age char(10) );

DESC student;

Alter table student DROP column age;

Alter table student Modify(rollno Number(10));

DESC student;

DROP TABLE student;

CREATE TABLE student (

name char(10),

rollno char(10) );

TRUNCATE TABLE student;

DML COMMANDS:

CREATE TABLE STUDENT(


name char(10),
rollno char(10),
marks char(10)
);
INSERT INTO STUDENT
VALUES ('REY','1','13');
INSERT INTO STUDENT
VALUES ('JEN','3','15');
INSERT INTO STUDENT
VALUES ('JAY','5','19');
SELECT * FROM STUDENT WHERE marks>15;
UPDATE STUDENT SET rollno=2 WHERE name='JEN';
DELETE FROM STUDENT WHERE name='REY';

Apply Integrity Constraints (NOT NULL, CHECK, UNIQUE, DEFAULT) for the
specified database system
CREATE TABLE STUDENT(
NAME CHAR(10) NOT NULL,
ROLLNO CHAR(10) NOT NULL
);

CREATE TABLE CUSTOMER (


ID CHAR(10) CHECK(ID>1),
NAME CHAR(10)
);

CREATE TABLE PERSON(


NAME CHAR(10) UNIQUE,
LOCATION CHAR(10) DEFAULT 'MUMBAI'
);

INSERT INTO PERSON


VALUES ('MAY','DELHI');

INSERT INTO PERSON(NAME)


VALUES('KIM');
SELECT*FROM PERSON;

INSERT INTO CUSTOMER


VALUES('3','RICK');

INSERT INTO STUDENT


VALUES('KAY','22');

Apply foreign key relationship and primary key constraints to relations in the
specified database system

CREATE TABLE SUPPLIER


( SUPPLIER_ID char(10) NOT NULL,
SUPPLIER_NAME char(50) NOT NULL,
CONSTRAINT SUPPLIER_PK PRIMARY KEY (SUPPLIER_ID)
);
CREATE TABLE PRODUCT
( PRODUCT_ID char(10) NOT NULL,
SUPPLIER_ID char(10) NOT NULL,
CONSTRAINT FK_SUPPLIER
FOREIGN KEY (SUPPLIER_ID)
REFERENCES SUPPLIER(SUPPLIER_ID));

INSERT INTO SUPPLIER


VALUES('11','LIAM');
INSERT INTO SUPPLIER
VALUES('22','PAIGE');
INSERT INTO PRODUCT
VALUES('1','11');
INSERT INTO PRODUCT
VALUES('2','22');
SELECT*FROM SUPPLIER;
SELECT*FROM PRODUCT;

Perform string manipulation based on _ and % operators on your considered


Database
create table person(
name char(10)
);
INSERT INTO person
VALUES('JERRY');
INSERT INTO person
VALUES('GEORGE');
INSERT INTO person
VALUES('ELAINE');
INSERT INTO person
VALUES('KRAMER');

SELECT*FROM person
WHERE name LIKE 'J%';
SELECT*FROM person
WHERE name LIKE '%E%';
SELECT*FROM person
WHERE name LIKE '_E%';
SELECT*FROM person
WHERE name LIKE 'E_%_%';
SELECT*FROM person
WHERE name NOT LIKE 'E%';
Perform and Implement outer Join operations on your database tables

CREATE TABLE PROFESSOR(


NAME CHAR(10),
SUBJECT CHAR(10),
DIVISION CHAR(5)
);
INSERT INTO PROFESSOR
VALUES('JAKE','BIOLOGY','A');
INSERT INTO PROFESSOR
VALUES('AMY','MATHS','A');
INSERT INTO PROFESSOR
VALUES('CHARLES','CHEMISTRY','B');

CREATE TABLE STUDENT(


NAME CHAR(10),
SUBJECT CHAR(10),
CLASS CHAR(5)
);
INSERT INTO STUDENT
VALUES('LUKE','CHEMISTRY','11');
INSERT INTO STUDENT
VALUES('ALEX','BIOLOGY','9');

SELECT DIVISION FROM


PROFESSOR LEFT OUTER JOIN STUDENT
ON PROFESSOR.SUBJECT=STUDENT.SUBJECT;

SELECT DIVISION FROM


PROFESSOR RIGHT OUTER JOIN STUDENT
ON PROFESSOR.SUBJECT=STUDENT.SUBJECT;

SELECT DIVISION FROM


PROFESSOR RIGHT OUTER JOIN STUDENT
ON PROFESSOR.SUBJECT(+)=STUDENT.SUBJECT;

SELECT CLASS FROM


PROFESSOR FULL OUTER JOIN STUDENT
ON PROFESSOR.SUBJECT=STUDENT.SUBJECT;
Perform and Implement inner Join operations on your database tables
CREATE TABLE PERSON(
NAME CHAR(10),
AGE CHAR(10)
);
CREATE TABLE STUDENT(
NAME CHAR(10),
ROLLNO CHAR(10),
AGE CHAR(10)
);
INSERT INTO PERSON
VALUES('KIAN','12');
INSERT INTO PERSON
VALUES('JAY','11');
INSERT INTO PERSON
VALUES('DENISE','12');
INSERT INTO PERSON
VALUES('WILL','13');
INSERT INTO STUDENT
VALUES('SALIM','33','12');
INSERT INTO STUDENT
VALUES('JAY','44','11');
INSERT INTO STUDENT
VALUES('DENISE','55','11');
INSERT INTO STUDENT
VALUES('AMIR','66','12');

SELECT* FROM
PERSON INNER JOIN STUDENT
ON PERSON.AGE = STUDENT.AGE;

Implement views and perform various operations on your database tables


CREATE TABLE EMP(
EMPNO CHAR(10),
ENAME CHAR(10),
SAL CHAR(10),
DEPTNO CHAR(10)
);
INSERT INTO EMP
VALUES('1','PHIL', '35000','1');
INSERT INTO EMP
VALUES('2','GLORIA', '79000','1');
INSERT INTO EMP
VALUES('3','ALEX', '95000','2');
INSERT INTO EMP
VALUES('4','HAYLEY', '22000','4');

CREATE VIEW EMP_NO_DEPT_NO AS SELECT EMPNO,DEPTNO FROM EMP;


select * from EMP_NO_DEPT_NO;

CREATE OR REPLACE VIEW EMP_NO_DEPT_NO AS SELECT EMPNO, DEPTNO, SAL FROM EMP;
select * from EMP_NO_DEPT_NO;

You might also like