Posts

Showing posts from 2024

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

Understanding DBA Roles: From Junior to Lead, and Beyond

  Types of DBAs and What They Do There are two main categories of Database Administrators (DBAs), though in many organizations these roles may overlap or evolve depending on team size and structure: 1. Software DBA (Development DBA) These DBAs focus on database design and development . Their main responsibilities include: Designing and creating database schemas — tables, indexes, relationships, and constraints. Writing and optimizing SQL queries, stored procedures, and functions to support application features. Collaborating closely with application developers to ensure efficient data access and maintain data integrity. Assisting in data modeling and setting up development and test environments . Ensuring that the database design supports business requirements for scalability and performance . Software DBAs tend to be involved in the planning and architecture phases of database projects, helping create a solid foundation for applications to interact with data ef...

How to Insert Data Into a Table in SQL Server

Once you have created your table, the next step is to insert data into it. The basic syntax to insert a single row is: INSERT INTO dbo.BRIAN (a, b) VALUES (1, 21); This inserts one record into the BRIAN table, setting column a to 1 and column b to 21. Inserting Multiple Rows Efficiently Instead of writing many separate INSERT statements like this: INSERT INTO dbo.BRIAN (a, b) VALUES (1, 21); INSERT INTO dbo.BRIAN (a, b) VALUES (39, 21); INSERT INTO dbo.BRIAN (a, b) VALUES (1998, 2001); -- and so on You can insert multiple rows with one statement like this: INSERT INTO dbo.BRIAN (a, b) VALUES (1, 21), (39, 21), (1998, 2001), (26, 2817), (21, 2938), (12, 21), (3939, 4848); This is cleaner, more efficient, and easier to maintain. Inserting Multiple Rows Using a Loop (T-SQL) Sometimes you might want to insert many rows dynamically, for example, inside a stored procedure or a script, or generate test data. You can do this with a loop using T-SQL'...

📊 Reading SQL Profiler Trace Files — And Why You Should Start Using Extended Events

SQL Server troubleshooting and performance tuning often require detailed insight into what’s happening under the hood. Historically, SQL Profiler and trace files were the go-to tools for this — and while they still have a place in the toolbox, there are now better, more modern ways to do deep diagnostics. In this post, we’ll walk through: How to work with SQL trace files. How to analyze traces using T-SQL. Combining Profiler traces with PerfMon. And most importantly: why Extended Events are the future of SQL diagnostics. 🧰 Part 1: Working with SQL Profiler Trace Files SQL Profiler allows you to trace and record database activity like queries, login attempts, lock escalations, etc. You can export this data into a .trc file and analyze it later. 📁 Opening Trace Files In SQL Profiler : Go to File → Open → Trace File . If your trace has multiple rollover files, Profiler will ask to open the next file when it reaches the end. 💡 Pro Tip: You can ...