Golang Tutorials - Learn Go Programming with Easy Step-by-Step Guides

Explore comprehensive Golang tutorials for beginners and advanced programmers. Learn Go programming with easy-to-follow, step-by-step guides, examples, and practical tips to master Go language quickly.

Create Table in SQL

Create Table in SQL

? CREATE TABLE in SQL

The CREATE TABLE statement is used to create a new table in the database.


? Basic Syntax

CREATE TABLE table_name (    column1 datatype [constraints],    column2 datatype [constraints],    ...);
  • table_name: Name of the new table.

  • column1, column2, ... : Names of columns.

  • datatype: Data type of the column (e.g., INT, VARCHAR, DATE).

  • [constraints]: Optional rules like PRIMARY KEY, NOT NULL, UNIQUE, etc.


? Example

CREATE TABLE employees (    id INT PRIMARY KEY,    first_name VARCHAR(50) NOT NULL,    last_name VARCHAR(50) NOT NULL,    email VARCHAR(100) UNIQUE,    hire_date DATE,    salary DECIMAL(10, 2) CHECK (salary > 0));

? Common Data Types

Data TypeDescription
INTInteger numbers
VARCHAR(n)Variable-length string (max n characters)
CHAR(n)Fixed-length string (n characters)
DATEDate
DECIMAL(p, s)Decimal number with precision and scale
BOOLEANTrue or False

? Common Constraints

  • PRIMARY KEY — Unique identifier for rows.

  • NOT NULL — Column must have a value.

  • UNIQUE — Values must be unique.

  • CHECK — Condition that values must satisfy.

  • FOREIGN KEY — Enforces referential integrity.


If you want, I can provide examples for specific SQL databases or more advanced table creation!

Disclaimer for AI-Generated Content:
The content provided in these tutorials is generated using artificial intelligence and is intended for educational purposes only.
html
docker
php
kubernetes
golang
mysql
postgresql
mariaDB
sql