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
- Open Microsoft SQL Server Management Studio.
- Connect to your server:
- Select a database
- Open a new Interface or Query page
- 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
Note: Optional additional features can be define.
STEP#2 – Create your Table
You’ll be able to create your table by typing the name of your table in the entry box.
Ok now, Open a new Query page (CTRL + N)
SELECT * FROM BtomerTable
Thank You!