You are on page 1of 4

Experiment 2:

Basic Operations on Databases and Tables

I: The motivation of experiment:


Understanding the basic operation of Databases and Tables. (DDL, create, show, and
drop).
II: The requirements of experiment:
a. Get understand the theory of relation among DB, DBMS, DBA.
b. Get understand the theory of relation among DB, tables, row, columns.
c. Get understand the theory of datatype, constraint, index.
III: The content and steps of the experiment:
1. Practicing (a) the datatype: int float and decimal; (b) the constraint: not null, primary key,
auto increment, default value.
(1) Using both ‘GUI’ and ‘SQL sentence’ methods to create a table name ‘product’
with 5 columns Including:
 id: the id of product, it is int type, primary key, not null, auto_increment.
 product_name: the name of product, it is varchar(20) type.
 product_num: the count of product, it is int type, not null, default value is 0.
 product_price: the price of product, it is float type, not null, default value is 0.
 product_weight: the weight of product, it is decimal(6,3) type, not null, default
value is 0.000.
(2) Insertimg those 4 products into table product.
id product_name product_num product_price product_weight
1 phone 20 7999.99 0.173kg
2 laptop 10 17999.99 2.45kg
3 tablet 33 3999.66 0.912kg
4 cable 11 default value default value

(3) Query the products you already inserted into the table

2. Practicing (a) the datatype: date, time, datetime, timestamp; (b) the constraint: not null,
primary key, auto increment, default value.
(1) Using both ‘GUI’ and ‘SQL’ sentence methods to create a table name student with 5
columns including:
 id: is the ID of student, it is int type, primary key, not null, auto increment.
 student_date: is the date of student is born, it is date type, not null;
 student_time: is the time of student is born, it is time type, not null;
 student_datetime: is the datetime of student is born, it is datetime type, not null;
 student_timestamp: is the timestamp of student is born, it is timestamp type, not
null, default value is current timestamp.

(2) Insert those three students into table student.


id student_date student_time student_datetime student_timestamp
1 2021-10-04 06:20:56 2021-10-04 2021-10-04
06:20:56 06:20:56
2 20211004 062056 20211004062056 20211004062056
3 2021-10-04 06:20:56 20211004 06:20:56 default value
4 current date current time current datetime current timestamp

(3) Query the students you already inserted into the table.

You might also like