You are on page 1of 4

DBT LAB

Create table state_audit with following column.


COLUMN_NAME DATA_TYPE LENGTH CONSTRAINT
=>STATE_ID CHARACTER 4 PRIMARY KEY
=>STATE_NAME CHARACTER 40 NOT NULL
=>UPDATE_TIMESTAMP (DATA TYPE TO STORE DATE AND TIME)

Step 1 :

Create table state_audit(

state_id varchar(4) primary key,


State_name varchar(40),
update_timestamp datetime );
1. Write a query to get the name of states in descending alphabetical order.
2. Write a query to get the countries where population is above 5000 and
below 7000.
3. Write a query to list state names with maximum literacy rate for each
country.
4. Write a query to add PRIMARY KEY in table countries on column
country_id.

5. Select all records from Countries table where country name is having ‘i’
as second last character.

6. Write a query to display highest and second highest literacy rate.

7. Write a query to perform join on country and state table which shows
all values from countries tables but only matching values from state
table.

8. Write a query to display country_name, population, state_name for


‘FRANCE’ and ‘RUSSIA’. If there is no state, display ‘NO STATES’.
Use approriate MySQL function/s.
9. Create index for country table on country name column
10.Write a view having following fields country name, country id,
population, state name, literacy rate where literacy rate is greater than
50.
11.Write a trigger to insert the value in state_audit table whenever a row is
deleted from state table. (Insert the timestamp when the trigger is
executed.)
12.Write a procedure to print number of days of month taking name of
month as parameter using switch case.(e.g. January, February)
13.Write a function to convert Celsius to Fahrenheit (formula:- multiply by 1.8
(or 9/5) and add 32).
MongoDB

NOTE: CREATE A DATABASE AND CONNECT TO IT USING


FOLLOWING COMMAND BEFORE ATTEMPTING QUESTIONS
BELOW -

use mydbd

14.Through a single command to create a collection with name “DAC” and


insert one document with following Key:Value pairs (1)
ModuleId: M101

ModuleName: DBT
TopicsCovered: MySQL and MongoDB

15.Display all the documents of “DAC” collection in ascending order of Topics


covered. (1)
16.Write a mongodb query to update the module name from “DBT” to “Data-
base”. (2)

You might also like