Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
100% found this document useful (2 votes)
3K views

DDL &DML Practice SQL

This document discusses various SQL commands used for data definition language (DDL) and data manipulation language (DML) operations on tables. For DDL, it describes creating tables based on given schemas, adding and modifying columns, adding constraints, dropping columns and tables. For DML, it covers inserting single and multiple rows without violating constraints, using substitution variables, difference between & and &&, filtering data for insertion, updating prices based on conditions, deleting rows based on conditions, and the purpose of commit statements.

Uploaded by

karthik1998
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
3K views

DDL &DML Practice SQL

This document discusses various SQL commands used for data definition language (DDL) and data manipulation language (DML) operations on tables. For DDL, it describes creating tables based on given schemas, adding and modifying columns, adding constraints, dropping columns and tables. For DML, it covers inserting single and multiple rows without violating constraints, using substitution variables, difference between & and &&, filtering data for insertion, updating prices based on conditions, deleting rows based on conditions, and the purpose of commit statements.

Uploaded by

karthik1998
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

DDL EXERCISE

Commands: CREATE TABLE, ALTER TABLE, DROP, TRUNCATE


Consider the following relations (schemas) for a database that keeps track of student enrollment
in courses and the books referenced for each course.

STUDENT (ROLLNO, NAME, DEPARTMENTCODE, DOB, EMAIL, ADDRESS)


COURSE (CCODE, CNAME, DEPARTMENTCODE)
ENROLL (ROLLNO, COURSECODE, SEMESTER, GRADE)
TEXTBOOK (COURSECODE, SEMESTER, BOOK_ISBN)
BOOKDETAILS (BOOK_ISBN, TITLE, PUBLISHER, AUTHOR)

(1) Identify the required key constraints and create tables for the above mentioned schemas.
(2) Add a column named “PRICE” in BOOKDETAILS.
(3) Add a check constraint in GRADE column in ENROLL table to restrict that it can hold
only (O, A+, A, B+, B, RA).
(4) Drop the column ADDRESS in STUDENT table.

(5) What happens if the column ADDRESS in STUDENT table is dropped with “Cascade”
option?
(6) Create tables DEPARTMENT and BRANCH with the following schema
DEPARTMENT (DCODE, DNAME, DLOCATION, BRANCHCODE)
BRANCH (BRANCHCODE, BNAME)

(7) Add a foreign key constraint to the STUDENT table for linking it with DEPARTMENT
table. Give a name to your foreign key.
(8) Difference between DROP table and TRUNCATE table
(9) Add a NOT NULL constraint to the AUTHOR column in BOOKDETAILS table.

(10) Add columns to BOOKDETAILS table named PUBLISHED_YEAR, EDITION and


make it NOT NULL.
(11) Display the constraint type and constraint name included in the table STUDENT.
(12) Modify the datatype (or size) of the CNAME column in COURSE TABLE.
(13) Rename the table BRANCH as BRANCH_DETAILS.
(14) Rename the column DOB in STUDENT table as BIRTHDATE.
(15) Drop BRANCH_DETAILS table with “Cascade” option.
DML Exercise
Commands: INSERT, INSERT ALL, DELETE, UPDATE

(1) Insert 10 records in each table without violating constraints using single row insert
(INSERT) and multiple row insert (INSERT ALL) command.
(2) Use substitution variable (&) in INSERT to read value for a variable.
(3) What is the difference between & and &&.
(4) Create a table called HIGHBOOK_PRICE with two columns (ISBN, Price). Insert the
records in the HIGHBOOK_PRICE table with the following details from BOOKDETAILS
table: “books whose price is greater than 3000”.
(5) Increase the price of all the books by 100, which were published after the year 2005.
(6) Delete all the first edition book details from the BOOKDETAILS table.
(7) Why we need of Commit Statement in DML commands?
(8) Modify the email id of a student whose roll number is specified by the user.

You might also like