How to Create Tables in SQL Server — Traditional and Graph Tables Explained
Now that you know how to create a database, let’s dive into creating tables — the core structure where your data lives. Basic Table Creation Example Here’s a simple example of creating a table named test inside a database called test : USE [test] GO CREATE TABLE [dbo].[test]( [id] INT IDENTITY(1,1) NOT NULL, [tracename] NVARCHAR(100) NULL, [enable] INT NULL, CONSTRAINT PK_test PRIMARY KEY (id) ) ON [PRIMARY] GO Explanation: id INT IDENTITY(1,1) NOT NULL — The id column is an integer, set to auto-increment starting from 1 ( IDENTITY(1,1) ), and it cannot be NULL. tracename NVARCHAR(100) NULL — This column can store Unicode text up to 100 characters and can be left empty ( NULL allowed). enable INT NULL — An integer column that also allows NULL values. PRIMARY KEY(id) — The primary key uniquely identifies each row. Here, the id column is the primary key. By default, if you don’t specify NULL or NOT NULL , SQL Server assumes the column c...