How to create new database and table in SQL server

By   Tewodros   Date Posted: Sep. 21, 2021  Hits: 892   Category:  Database   Total Comment: 0             A+ A-


side

Create new database

Syntax:

create database {db name}

Example:

create database BankApp

Create new table

create table  {table name}(

  {column name} {data type}    {optional/required},

  {column name} {data type} {optional/required},

  {column name} {data type} {optional/required},

  {column name} {data type} {optional/required}

)

Note: {optional/required}  specify using null which means optional, but not null means required 

Example:

create table customer (

 id  int not null,

 firstname varchar(50)  null

)

 

CREATE TABLE Account (

     ID int IDENTITY(1,1) NOT NULL,

     DepositAmount float NOT NULL,

     WithdrawAmount float NULL,

     TransactionDate datetime NULL,

     MerchantName nvarchar(50) NOT NULL,

     MerchantAddress nvarchar(50) NULL,

     MerchantPhone nvarchar(50) NULL,

     CustomerName nvarchar(50) NULL,

     CustomerAddress nvarchar(50) NULL,

     CustomerPhone nvarchar(50) NULL,

     LastUpdateDate datetime] NULL,

     LastUpdateBy nvarchar(50) NULL

)

 

Identity : will make sure you will have nonrepeating numbers for the Id

Default Value: will set the default value of the column

example: We want LastUpdateDate to be the date the data was last touched. In this case we can set the default value in SQL server designer to be getdate(). getdate()  is a sql function to get the current date.


Tags



Back to Top



Related Blogs






Please fill all fields that are required and click Add Comment button.

Name:*
Email:*
Comment:*
(Only 2000 char allowed)


Security Code:* fdutya

Back to Top