In this article, we will learn the concept of SQL tables and then work on how we can create tables with different techniques in SQL Server.

A relational database model is one of the most used data models to store and process the data. Tables are the essential elements of a database. In this context, tables are the database objects that hold the data in the relational databases. A database contains one or more tables and these tables can be modeled as relational. The tables come into existence from the columns and every column must have a name and a data type. These columns store data according to the defined data types and these data records are called rows. The following illustration shows an example of a table structure.

Anatomy of a SQL table

As we can see, the Persons table consists of IdNameSurname, and Age columns. These columns hold either numeric or text data according to defined data types. Now, we will learn how to create tables with different techniques.

Create a table using SQL Server Management Studio (SSMS)

SQL Server Management Studio is an IDE (integrated development environment) that helps to manage SQL Server and building T-SQL queries. So, it is very easy to create a table through the SSMS. After connecting to the database, we right-click on the Tables folder and select the New on the pop-up menu and click the **Table **option.

Create a table using SSMS

New Table customized window will be shownto create a table quickly. At the same time, we can find the properties of the selected column at the bottom of the same screen.

Property of a column in SSMS

On the New Table window, we can define the columns with names and data types. Each column must have a data type and a unique name.

Designing a table on SSMS

Tip: When we checked the Allow Nulls option enables us to store null values to the associated column.

When we right-click on any column, we can set some options for this column. The right-arrow indicates which column we are working on.

Changing the primary key setting of a column in SSMS

Set Primary Key: Theprimary key is a value or combination of values that help to uniquely identify each row on the table. For this table, we will set the Id column as a primary key. After setting a column as a primary key, a key sign will be appeared on the column.

Set a column as a primary key

When we try to check the Allow Nulls option for a column that has been set as a primary key, SSMS returns an error.

Primary key columns do not allow to null values

As we stated, SQL tables allow us to specify composite primary keys. Only we need to select more than one column with the help of the shift key and click the Set Primary Key option.

Set a column as primary key

The key sign will be shown for these multiple columns.

How to create a composite primary key in SQL Server

#development #sql commands #sql server management studio (ssms) #t-sql #sql

An introduction to SQL tables
1.45 GEEK