Home> Database> SQL> body text

What command is used to create a basic table in sql

下次还敢
Release: 2024-05-07 04:39:14
Original
840 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, useCREATE TABLEcommand to create basic tables.

Syntax:

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] );
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 namedcustomerswithcustomer_id(primary key),first_name,last_nameandemailcolumns:

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 );
Copy after login

Note:

  • Primary Key Columns are defined usingPRIMARY KEYconstraints.
  • Unique index columns are defined usingUNIQUEconstraints.
  • Auto-increment columns are defined using theAUTO_INCREMENTkeyword.

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
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!