Home > Database > SQL > body text

What command is used to create a basic table in sql

下次还敢
Release: 2024-05-07 04:39:14
Original
885 people have browsed it

The command to create a basic table in SQL is CREATE TABLE. It is used to create a basic table with column names, data types and constraints like NOT NULL, DEFAULT.

What command is used to create a basic table in sql

Commands to create basic tables in SQL

In SQL, use CREATE TABLE command to create basic tables.

Syntax:

<code>CREATE TABLE table_name (
  column_name1 data_type [NOT NULL | NULL] [DEFAULT default_value],
  column_name2 data_type [NOT NULL | NULL] [DEFAULT default_value],
  ...
  column_nameN data_type [NOT NULL | NULL] [DEFAULT default_value]
);</code>
Copy after login

Parameters:

  • table_name: Table name.
  • column_name: Column name.
  • data_type: The data type of the column (for example, INT, VARCHAR, DATE).
  • NOT NULL | NULL: Specify whether the column allows NULL values.
  • DEFAULT default_value: Specifies the default value of the column (if specified).

Example:

Create a table named customers with customer_id (primary key), first_name, last_name and email columns:

<code class="sql">CREATE TABLE customers (
  customer_id INT NOT NULL AUTO_INCREMENT,
  first_name VARCHAR(50) NOT NULL,
  last_name VARCHAR(50) NOT NULL,
  email VARCHAR(100) UNIQUE NOT NULL
);</code>
Copy after login

Note:

  • Primary Key Columns are defined using PRIMARY KEY constraints.
  • Unique index columns are defined using UNIQUE constraints.
  • Auto-increment columns are defined using the AUTO_INCREMENT keyword.

The above is the detailed content of What command is used to create a basic table in sql. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!