Databases 3 min read

Beginner’s Guide: Essential Table Operations – Create, View, and Delete Tables

This tutorial walks beginners through the fundamentals of database tables—explaining fields, data types, and constraints—while demonstrating how to create a standard user table, view its structure, and safely delete it using SQL Server commands.

liandk
liandk
liandk
Beginner’s Guide: Essential Table Operations – Create, View, and Delete Tables

Why tables matter

In a database, the database itself is like a folder, while a table corresponds to an Excel sheet that stores concrete data such as users, orders, or products.

Three essential elements of a table

Each table requires a field name , a data type , and constraint rules .

Common data types

int : integer values (e.g., ID, age, quantity)

varchar(n) : variable‑length strings (e.g., name, phone, address)

datetime : date‑time values (e.g., creation time, update time)

decimal(m,n) : fixed‑point numbers for amounts, prices, rates

Typical scenarios

Designing business‑system tables

Building test or practice tables

Inspecting table structures and field information

Practical example – a generic user table

-- Create user information table
CREATE TABLE UserInfo(
    UserID INT PRIMARY KEY IDENTITY(1,1), -- primary key, auto‑increment
    UserName VARCHAR(20) NOT NULL,        -- username, not null
    Phone VARCHAR(11),                    -- phone number
    Age INT,                              -- age
    CreateTime DATETIME DEFAULT GETDATE() -- default current time
);
GO

-- List all tables in the current database
SELECT name FROM sys.tables;

-- Show detailed structure of the user table
sp_help 'UserInfo';

-- Delete the table if it exists
DROP TABLE IF EXISTS UserInfo;
GO

Key points for beginners

PRIMARY KEY : ensures each row is unique; a table can have only one primary key.

IDENTITY(1,1) : auto‑increments the key value, eliminating manual ID entry.

NOT NULL : forces a column to contain a value, preventing empty or dirty data.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Data TypesSQL ServerSQL BasicsTable ConstraintsDatabase Tables
liandk
Written by

liandk

Seasoned Java and mobile developer with years of experience, specializing in mini‑programs, public accounts, and full‑stack front‑end development. In the AI era, I continuously learn to broaden my knowledge and evolve. I revived a public account I started a decade ago during a dessert‑startup venture, using code as a vessel and knowledge as a companion. I share personal projects, technical articles, programming tips, and growth insights—let’s improve together and set sail.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.