Databases 22 min read

Comprehensive SQL Server Cheat Sheet: Basics, Advanced Queries, Administration, and Replication

This article provides a detailed collection of SQL Server commands and techniques covering database creation, table and index management, common DML statements, advanced set operators, various join types, grouping, pagination, maintenance tasks, replication setup, linked‑server usage, and a synchronization stored procedure.

Java Captain
Java Captain
Java Captain
Comprehensive SQL Server Cheat Sheet: Basics, Advanced Queries, Administration, and Replication

This guide starts with fundamental SQL Server operations such as creating and dropping databases ( CREATE DATABASE database_name , DROP DATABASE dbname ), creating and deleting tables ( CREATE TABLE tabname(...) , DROP TABLE tabname ), adding columns, primary keys, indexes, and views.

It then lists essential DML statements for selecting, inserting, updating, deleting, and aggregating data, followed by advanced set operators (UNION, EXCEPT, INTERSECT) and join variations (LEFT, RIGHT, FULL OUTER). Grouping, ordering, and pagination techniques are also demonstrated.

Administrative commands for database maintenance are included, such as rebuilding indexes ( DBCC REINDEX ), shrinking databases and logs ( DBCC SHRINKDB , DBCC SHRINKFILE ), verifying backups, and repairing databases.

The article explains how to use linked servers and remote queries with sp_addlinkedserver , openrowset , openquery , and opendatasource to copy, query, and synchronize data across servers.

A complete replication setup procedure for SQL Server 2000 is described, covering preparation steps, publishing configuration, creating publications, and scheduling jobs with SQL Server Agent.

Finally, a sample synchronization stored procedure ( CREATE PROC p_process AS ... ) is provided to update, insert, and delete records between two databases, illustrating practical use of linked servers and distributed transactions.

SQLQuery Optimizationdata replicationDatabase AdministrationSQL ServerT-SQLLinked Server
Java Captain
Written by

Java Captain

Focused on Java technologies: SSM, the Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading; occasionally covers DevOps tools like Jenkins, Nexus, Docker, ELK; shares practical tech insights and is dedicated to full‑stack Java development.

0 followers
Reader feedback

How this landed with the community

login 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.