There are 3 kinds of commands in the deletion purposes like DROP, TRUNCATE and DELETE.ĭROP table deletes the whole records as well as the structure/index of the table. (1003, ‘Sachin’, ‘Tendulkar’, 9878749867),Īlter is basically for doing manipulation in a table like adding a new column, changing the name of an existing column, dropping an existing column, rename table name, and for adding constraints. Step 1: Creating the table with these fields. Let’s create the below ‘customer’ table in the database: Cust_id Instead, we should use underscore like student_table, customer_order, etc.
![mysql create table mysql create table](https://www.tutorialgateway.org/wp-content/uploads/MySQL-Create-Table-Example-16.png)
![mysql create table mysql create table](https://content.endurance.com/img/mysql_2018_4.png)
This table can consists many kind of datatypes as INT(), SMALLINT(), BIGINT(), CHAR(), VARCHAR(), DATE(), TIME(), TIMESTAMP(), BOOLEAN() etc. If there is a common field that exists between 2 tables, we can join both the tables using multiple types of join commands like inner join, outer join, left & right join. In the child table, the primary key is one attribute from the parent table, which may also be called a foreign key as this key establishes a relationship between 2 tables. There must be a primary key in each table which is a unique identification of each record. In the table in MySQL in this there are two kinds of tables, called parent and child tables. You can verify the above created table using the DESC statement too.Tables are the structured format of saving records in a database as this is easy to access and can be maintained by drawing relations between multiple tables.
![mysql create table mysql create table](https://i.ytimg.com/vi/XJ7dlwHuVUk/maxresdefault.jpg)
Mysql> CREATE TABLE sample LIKE Employee Exampleįollowing query create a new table sample same as the table Employee Where, table_name is the name of the table you need to create and old_table_name is the name of the table from which you need to create the new one.
![mysql create table mysql create table](https://www.tutorialgateway.org/wp-content/uploads/MySQL-Create-Table-Example-3.png)
You can also create a table using the existing table (with same definition), following is the syntax to do so −ĬREATE TABLE table_name Mysql> CREATE TABLE Test(Name VARCHAR(255)) If you use the IF NOT EXISTS clause along with the CREATE statement as shown below a new table will be created and if a table with the given name, already exists the query will be ignored. Mysql> CREATE TABLE Employee(Name VARCHAR(255)) ĮRROR 1050 (42S01): Table 'employee' already exists If you try to create a table with an existing name an error will be generated − The SHOW TABLES statements gives you the list of tables in the current database, if the creation is successful, you can see the name of the above created table in it. Exampleįollowing query creates a table with name Employee − Where, table_name is the name of the table you need to create, column1, column2, column3, …….… columnN are the names of the columns and datatype is the name of the datatypes of the respective columns. Syntaxįollowing is the syntax to create a table in MySQL − Here, you need to specify the name of the table and, definition (name and datatype) of each column. The CREATE TABLE statement is used to create tables in MYSQL database.