Create Table SQL Server

Create Table SQL Server

Hi friends, in this post we will learn to Create Table SQL Server. Creating table in SQL Server is very easy. Tables consist rows and columns, columns name specify the name of columns and rows contains data in them. Column has data_type parameter which specifies what type of data the column can hold (e.g. varchar(20), integer etc.).

Earlier we had discussed about Schema In SQL ServerSQL Server OperatorsData Type in SQL Server and Drop-Delete SQL Server Database Using Management Studio or Query.

Create table SQL Server Query:

----USE DATABASE IN WHICH WE WANT TO CREATE TABLE----
USE Hightechnology
GO

----CREATE TABLE NAME DEFINED FIRST---
CREATE TABLE STUDENT
(
ID INT PRIMARY KEY, ----IT IS PRIMARY KEY, IT DOES NOT ALLOW NULL VALUE----
NAME VARCHAR(20) NOT NULL,----NOT NULL DOES NOT ALLOW NULL VALUE----
CLASS CHAR(10) NOT NULL,
PERMADDRESS VARCHAR(50) NOT NULL,
TEMPADDRESS VARCHAR(50) NULL  ----DOES ALLOW NULL VALUE-----
)
GO
----TABLE NAME STUDENT WILL BE CREATED IN HIGHTECHNOLOGY DATABASE WITH 5 COLUMNS----

Create table SQL Server Management Studio:

1. Open SQL Server Management Studio, and connect to SQL Server.

2. Expand Database name > Right click on tables and click on New Table.

create table sql server

3. Now enter Column name, Data types and either they are null or not null.

create table sql server query

4. Set Primary key, foreign key etc. if you want.

create table sql server management studio

5. Now click on save icon, it will ask you table name. Enter table name.

create table in sql server