Flash Sale: Flat 70% + Addl. 25% Off on all Courses | Use Coupon DS25 in Checkout | Offer Expires In

  Enroll Now

Creating and Dropping a table

A table is an object which stored data in rows and columns.

The table creation command requires the following details:
Name of the table Name of the fields Definitions for each field

Basic Syntax:

create table table_name (
  column_name1 column_type1 [default <values>]
  ,column_name1 column_type1 [default <values>]
 );

Full Syntax:

https://dev.mysql.com/doc/refman/8.0/en/create-table.html

Example:

use mydb1
create table deptt(
 depid int not null,
 depname varchar(30) not null default 'New',
 depopendate datetime not null default CURRENT_TIMESTAMP
);

Try creating above table and if succeeds, you will see a message like below one, else you will see relevant error message:
Query OK, 0 rows affected (0.01 sec)

View the table definition using below commands:

describe deptt;

OR

show create table deptt;
show columns from deptt;
show table status like 'deptt';

Try selecting the data from the table. You would see 0 rows because no data has been inserted yet into the table.

select * from departmt;

Dropping a table
Tables can be dropped using 'drop table' command. A table can not be dropped if it is being used by someone else or if the table has child tables enforced by Foreign Keys and child table has records.

drop table deptt;

No hints are availble for this assesment

Answer is not availble for this assesment

Loading comments...