Only Few Seats Left for Advanced Certification Courses on Data Science, ML & AI by E&ICT Academy IIT Roorkee

  Apply 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:


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;


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...