How to create a table using command prompt?

While you are creating a table using command prompt, you should have to take care about the following points

  • Name of the table
  • Name of the fields
  • Definitions for each field

Execute below command for creating a table.

create table Employee(
 emp_id INT NOT NULL AUTO_INCREMENT, 
 emp_name VARCHAR(100) NOT NULL, 
 emp_designation VARCHAR(40) NOT NULL, 
 joining_date DATE, 
    PRIMARY KEY (emp_id ) 
 ); 
  • Field Attribute NOT NULL is being used because we do not want this field to be NULL. So, if a user will try to create a record with a NULL value, then MySQL will raise an error.
  • Field Attribute AUTO_INCREMENT tell to MySQL to go ahead and add the next available number to the id field.
  • Keyword PRIMARY KEY is used to define a column as a primary key. You can use multiple columns separated by a comma to define a primary key.

NOTE − MySQL does not terminate a command until you give a semicolon (;) at the end of SQL command.

 

Leave a Reply

Your email address will not be published. Required fields are marked *