DATABASE CONCEPTS
To view the list of existing databases in mysql server
mysql> show databases;
To create a new database
mysql> create database cs12;
To use the database
mysql> use cs12;
To create a table
mysql> create table product
-> (
-> product_id char(7) primary key,
-> product_name varchar(30) not null,
-> price float(8,2),
-> quantity int(4),
-> dom date,
-> mfc varchar(30)
-> );
To view the structure of the table
mysql> desc product;
To insert records in a table
⟶ where the sequence of the column is known
mysql> insert into product
-> values('p001','cake','50','100','2024-10-20','brittania');
⟶ When the sequence of columns is not known
⟶ When we want to insert the values in specific column only
To view the records
⟶ Displaying all the rows and all the columns
⟶ To view selective columns but all the rows
⟶ To display all the columns but selective rows
⟶ To display specific rows and specific columns from the table
Q1. Write the command to create a table student with the following columns. Choose
appropriate data types and constraints for the table. Write the command to insert at
least 5 records.
mysql> insert into student
-> values('KC/7708','Musa','2006-11-19','XII','def.gmail.com','9868501882');
Query OK, 1 row affected (0.01 sec)
mysql> insert into student
-> values('KC/7707','Rachel','2006-12-9','XII','ghi.gmail.com','7678649818');
Query OK, 1 row affected (0.01 sec)
mysql> insert into student
-> values('KC/7706','Amber','2006-9-12','XII','jkl.gmail.com','8368727176');
Query OK, 1 row affected (0.01 sec)
mysql> insert into student
-> values('KC/7705','Georgia','2006-5-24','XII','mno.gmail.com','8851484499');
Query OK, 1 row affected (0.01 sec)
mysql> select * from student;
Q2.Write the command to display a list of all the products manufactured before 1st
October 2024
Q3. Display product name and manufacturer of all the products which are not
manufactured by ‘Nestle’
Q4. Write the command to display the list of all the products whose cost is in the
range of 30 to 100.
Q5. write the command to display the list of students who were born in the year 2008
Q6.Write the command to display pname and quantity of all the products having
price above 25 with quantity less than 10
Q7.Write a command to display pname and manufacturer of all the products which
are manufactured by nestle and itc.
Q8.Display the list of all the students who are studying in class 11 or 12
Q9. Write a command list of all the products whose price does not lie in the range of
30-100