HOW TO CREATE A TABLE IN SQL SERVER (2 Method)

How to create a table in sql server? There are two methods for creating a table. Okay Now, The first method is to create the table by opening a Query page. The two method is to create the table by opening a Interface page.

STEPS

  1. Open Microsoft SQL Server Management Studio.
  2. Connect to your server:
  3. Select a database
  4. Open a new Interface or Query page
  5. Creating a table

CREATE TABLE – SYNTAX

The basic syntax of the CREATE TABLE statement. Creating a table with script

  • Table Name: Give the name of a table.
  • Column Name: The Name of the column you want to see in the table
  • Data Type: Define a property to the column.
    Example: INT, VARHCAR(number), DECIMAL, FLOAT…
  • Optional additional feature so PRIMARY KEY, PERSISTED, IDENTITY…
CREATE TABLE table_name(
   columnName1 datatype,
   columnName2 datatype,
   columnName3 datatype,
   ...
   PRIMARY KEY( one or more columns )
);

HOW TO CREATE A TABLE WITH SCRIPT

Let’s create a simple table. Just a standard.

CREATE TABLE Customer(
  [Id] INT IDENTITY(1,1) PRIMARY KEY NOT NULL, 
  [CustomerName] VARCHAR(50) NOT NULL,
  [Address] NVARCHAR(100),
  [Price] FLOAT
)
--F5 EXECUTE

Which creates a Customer table with an Id as a primary key and NOT NULL are the constraints showing that these fields cannot be NULL while creating records in this table 

F5 Execute — output : Commands completed successfully.

SELECT * FROM Customer

HOW TO CREATE A TABLE WITH INTERFACE

  • Select a Server and under the Object Explorer, you’ll see the Databases Folder.
  • Select a Database and Right click on that folder and then select Tables From the drop-down list.
  • Column Name, Data Type, Is it checkbox allow Null?
  • Optional additional features can be defined

STEP#1 – Open an interface for creating a table

create a table on interface with sql server

Note: Optional additional features can be define.

create a table on properties with sql server

STEP#2 – Create your Table

You’ll be able to create your table by typing the name of your table in the entry box.

create table by name of table

Ok now, Open a new Query page (CTRL + N)

SELECT * FROM BtomerTable

Thank You!

Leave a Reply