Before to start to create table in SQL Server we have to know some basic points regarding SQL Table. We use MS SQL Server table to store the information / data. SQL Server allows creating 2,147,483,647 tables in single database, where one table can have 1024 columns. While creating database we must have to have basic knowledge of data types in SQL Server , so we can store required data properly.
Table of Contents
Tables are use to store data in rows and columns format. It's very easy to create table in SQL Server,
We can create table in SQL Server by two different ways.
1) Create table in SQL Server using command.
2) Create table in SQL Server using UI.
Below table is called as physical table because it is physically available in database and scope of this table is till database remain in server.
Before create table create the database and after that, open new query editor by right click on respected database. Find below image.
Follow the steps to create the table.
Step 1 : Open text editor as above image show.
Step 2 : Write the create table command. Example given below.
Syntax to create table in SQL Server
Create table in SQL Server with primary key get cover in below example because Id is primary key of table. Also we cover create table in SQL Server with primary key and identity because Id columns set as identity(1, 1).
Create table in SQL Server with example
See, after execution of query in below image new table created tblStudentMaster in StudentDB.
Step 3 : Once table get created, now insert data in SQL Server table, to insert data in table refer the below command.
Syntax to insert data in SQL Server table
Example
Output
Note : If you observe the above statement you will see that we not provide the ID columns value using query.
Because ID is primary key of tblStudentMaster and ID columns we set as identity columns, it means we not need to provide the value to ID
column at time of data insertion. For more example refer above create statement of tblStudentMaster.
At the time of data insertion in SQL Server table we provides string value in single cote ex. 'Vikrant Dalvi'
and numerical value without single cote ex. 10
Lear how to create primary key and foreign key in SQL Server with examples.
Example
Output
In above example City columns we add, it shows null values default because while creating columns we specify NULL keyword. It mean that columns can have store null values in it.
Find below example which explain how to rename exiting column in SQL Server table with command.
Example
Output
Find below example which explain how to remove column from existing table in SQL Server table with command.
Example
Output
Note : We insert data in Student table. Now we will insert data in to tblStudentMarksDetail table. We are trying to show insert data in table using UI and crate relation in two table.
Step 5 : Insert the values in table and click enter, new row will create automatically.Lear how to create primary key and foreign key in SQL Server with examples.
If you select the both table data (tblStudentMaster, tblStudentMarksDetail) in view data will look like. Select data from both table for comparison purpose.To learn more about table creation click on Microsoft.