SQL Server codemodes

Create Table in SQL Server

In SQL Server by Baqir Ali

After creating database in SQL Server Now it is time to create a table.

Scenario

Create a table that stores basic information about a user that can log in to an application the followings are the columns or fields needed in that table.

Field NameData TypeDescription
userIdvarchar(50)it stores user id information, it is unique and also primary key
userPwdvarchar(50)it stores user password
userNamevarchar(50)it stores user name
userPhonevarchar(50)it stores user phone
userEmailvarchar(50)it stores user Email
userStatusbitit stores user status either true or false

Solution

There are two ways to solve this problem. It can be either graphically or through code.

Create table using GUI in SQL Server Management Studio

  1. Start SQL Server Management Studio
  2. Expand the database name codemodes
  3. Right click on the tables click on Table
  4. And fill like the following
SQL Server Table

Now set the userId as primary key: Right-click on the row and click on Set Primary key

SQL Server Table

Now save the changes and name the table as user

Create table using Query Window in SQL Server Management Studio

CREATE TABLE [dbo].[user](
[userId] nvarchar Primary Key,
[userPwd] nvarchar NULL,
[userName] nvarchar NULL,
[userPhone] nvarchar NULL,
[userEmail] nvarchar NULL,
[userStatus] [bit] NULL,
)

Now press F5 or click on Execute button

Support us by sharing this post