Home  >  Article  >  Database  >  How to create a table with navicat command

How to create a table with navicat command

下次还敢
下次还敢Original
2024-04-23 19:27:15932browse

By executing the CREATE TABLE command, you can create a table in Navicat, which contains column names, data types and constraints (such as non-null, default values). For example, you can create an employees table with the id, name, and salary columns by CREATE TABLE employees (id INT NOT NULL AUTO_INCREMENT, name VARCHAR(255) NOT NULL, salary DECIMAL(10,2) NOT NULL DEFAULT 0.00).

How to create a table with navicat command

Navicat creates a table using commands

In Navicat, you can create a table by executing the following command:

<code>CREATE TABLE table_name (
  column1 data_type [NOT NULL | NULL] [DEFAULT default_value],
  column2 data_type [NOT NULL | NULL] [DEFAULT default_value],
  ...
);</code>

Parameter description:

  • table_name: The name of the table to be created.
  • column1, column2...: The name of the column to be created.
  • data_type: The data type of the column, such as INT, VARCHAR, DATE, etc.
  • NOT NULL: means that the value of this column cannot be empty.
  • NULL: indicates that the value of this column can be empty.
  • DEFAULT default_value: Specify the default value of the column (optional).

Example:

To create a table named "employees" with columns "id", "name" and "salary", you can use The following command:

<code>CREATE TABLE employees (
  id INT NOT NULL AUTO_INCREMENT,
  name VARCHAR(255) NOT NULL,
  salary DECIMAL(10,2) NOT NULL DEFAULT 0.00
);</code>

Note:

  • Make sure you are connected to the correct database before executing the command.
  • For auto-increment primary key columns, you can use the "AUTO_INCREMENT" keyword.
  • "VARCHAR(n)" Specifies the maximum length of the string column.
  • "DECIMAL(p,s)" specifies the precision (p) and decimal places (s) of the decimal column.
  • You can specify the primary key by adding the "PRIMARY KEY" keyword after the column name.
  • You can specify a unique index by adding the "UNIQUE" keyword after the column name.

The above is the detailed content of How to create a table with navicat command. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn