You need to decide on which database you are going to create the table. Here, you can see the databases that are created previously. Now you need to follow the below steps for table creation.įirst, navigate to the Navigation window and click on the Schema tab. Once connected, you will see the screen something like this.
Create database mysql workbench how to#
You can follow our tutorial on how to connect MySQL using MySQL Workbench. To create a new table in MySQL, you need to launch the MySQL Workbench and log in using the username and password. MySQL Workbench is a GUI tool which is can be used to create tables, views, indexes quickly and efficiently. In order to table structure, you need to use the following command. This will give output as below: mysql> show tables To confirm if the table is created, you can use the following command. Visual representation of MySQL CREATE TABLE: Gender varchar(6) NOT NULL DEFAULT 'male', Registration_no int(10) NOT NULL AUTO_INCREMENT,įirst_name varchar(50) NOT NULL DEFAULT '', CREATE TABLE IF NOT EXISTS student_details ( In the below example, we are creating a student_details table in the university database. mysql> use university įinally, run the CREATE TABLE statement to create a new table into the selected database. Now, select the university database as shown below. List the available databases as below: mysql> show databases Second, select the database where you want to create the table as follows. Note: you can use any other user who has the CREATE TABLE privileges on the database.
Create database mysql workbench password#
Type the root user password and press the enter key. It will ask for the root password which you have kept during the MySQL installation. MySQL provides two different ways to create a new table into the database.ġ) Creating Table using MySQL Command Line Clientįirst, launch the MySQL Command Line Client tool and log in with a user who has the CREATE TABLE privileges on the database where you want to create the table. The default is the InnoDB storage engine. You can specify any supported engine such as InnoDB, MyISAM, etc. you can specify the storage engine for the table in the ENGINE clause. PRIMARY KEY ( column_1, column_2.)įourth, optionally. Third, after the column lists, you can specify the table constraints such as PRIMARY KEY, FOREIGN KEY, UNIQUE, and CHECK.įor example, if you want to declare the primary key on the combination of two or more columns, you can use the following syntax. In MySQL, the initial value for the AUTO_INCREMENT is 1 and each table can have a maximum of one AUTO_INCREMENT column. Iv) The AUTO_INCREMENT specifies that the value of the column is automatically incremented by one whenever a new row is inserted into the table. Iii) The optional parameter DEFAULT specifies the default value for the column that means if a value is not provided for the column during data insertion, the default value will be inserted.
Besides NOT NULL, you can specify constraints such as UNIQUE, CHECK, etc. Ii) After the column name and data type, you optionally specify the NOT NULL constraint which ensures that the column will not contain any null value. Each column has a data type and optional size e.g.
I) The column_name denotes the name of the column. Each column is separated by commas.īelow is the generic syntax of a column definition: column_name data_type(length) Second, you specify the list of columns required for the table along with the column’s data types and column’s constraints. Optionally, you can use IF NOT EXIST after the CREATE TABLE keywords, the MySQL will not throw any error in case of a duplicate table. If the table name you specify already exists in the database, MySQL throws an error. The name of the table should be unique within the database. Let’s understand each term’s in great detail.įirst, you specify the name of the table after the CREATE TABLE keywords. The following illustration shows the generic syntax for creating a table in the MySQL database. The CREATE TABLE statement is used to create a new table in the MySQL database. So, we must have a very clear idea about creating a table in any relational database. MySQL CREATE TABLE IntroductionĪ table in any relational database is a basic element that holds data in the form of rows and columns. Summary: in this tutorial, you will learn how to create a new table in the MySQL database using the CREATE TABLE statement.