0% found this document useful (0 votes)
17 views

SQL Server Notes

The document describes creating tables for a banking database. It includes tables for customers, branches, accounts, loans, depositors, and borrowers. Primary and foreign keys are defined to link the tables together. Sample data is provided to insert into the customer table.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

SQL Server Notes

The document describes creating tables for a banking database. It includes tables for customers, branches, accounts, loans, depositors, and borrowers. Primary and foreign keys are defined to link the tables together. Sample data is provided to insert into the customer table.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Data types

Characters
1) Unicode : All Language >1 char – 2Bytes ( Ihsan Bey- 14Byest)
Data Types : 1:- nChar (4000), 2:- nvarChar (4000), 2:- 3:- nvarChar (Max)... Upto 1GB
2)Non Unicode: English 1 char – 18Bytes ( Ihsan Bey- 7Byest)
Data Types : 1:- Char (8000) ... Fixed Lenght Data , 2:- varChar (8000) ... Variable Lenght
Data, 3:- varChar (Max)... Up to 2GB
IT_Parivaar
--------------------------------------------------------------------------------------
-
Name :Code for School
Author :Mohammad Ihsan Baqaakhil
Date :Feb 28, 2024

Porpuse :This script will create Db and a few table in it to store info
about School
--------------------------------------------------------------------------------------
--

--- Create Database Name


Create Database Course_Master

---Create Tables
Create table Course_Master
(
CID inter primary key,
CourseName varchar(40) not null,
Category char(1) null ,Basic/Medium/Advanced
Fee Smallmoney not null; Fee cann not be negative

)
go

--- Create Master_Cours


create table Master_Course

(
CID int primary key,
CourseName varchar(40) not null,
Category char(1) not null check (Category ='B' or Category ='M' or Category ='A'),
Fee Smallmoney not null check (Fee> 0)
)

--- Find Schema


sp_help Master_Course

select * from Master_Course


go

---Insert Data
insert into Course_Master values (10,'Java','B','5000' )
insert into Course_Master values (20,'AdvJava','B','25000' )
insert into Course_Master values (30,'BigData','A','67000' )
insert into Course_Master values (40,'SQL Server','M','23000' )

insert into Course_Master values (50,'Oracle','M','13000' )


insert into Course_Master values (60,'Python','M','77000' )
insert into Course_Master values (70,'MSIB','B','41000' )
insert into Course_Master values (80,'Data Seinces','A','55000' )
go

--- Create CourseStudents


create table CourseStudents
(
SID int primary key,
Name varchar(40) not Null,
Orinig char(10) Not Null check (Orinig = 'L' or Orinig = 'F' ),
Type char(1) not Null check (Type = 'U' or type = 'G' )
)
go

select * from CourseStudents


go

insert into CourseStudents values (1,'Mohammad Ihsan Baqaakhil','F','G' )


insert into CourseStudents values (2,'Rafiq Rahmani','F','G' )
insert into CourseStudents values (3,'Mohammad Sabor','F','G' )
insert into CourseStudents values (4,'Khalid Khaliqi','F','G' )
insert into CourseStudents values (5,'Yonus Yurekturk','F','G' )
go

---Create Students Master Table


Create table Students_Master
(
SID tinyint primary key,
Name varchar(40) not Null,
Orinig char(10) Not Null check (Orinig = 'L' or Orinig = 'F' ),
Type char(1) not Null check (Type = 'U' or type = 'G' )
)
go

Select * from Students_Master


go

---Insert data
insert into Students_Master values (1,'HasanKhan','F','G' )
insert into Students_Master values (2,'Ghulam Rahimi','L','U' )
insert into Students_Master values (3,'Haroon Ahmadi','F','U' )
insert into Students_Master values (4,'Tawab Nawab','L','G' )
insert into Students_Master values (5,'Farhad Matin','L','G' )
insert into Students_Master values (6,'Tahir Zahiri','F','G' )
go

---Enrollment_Master
create table Enrolment_Master
(
CID int not null Foreign key References Course_Master(CID),
SID tinyint not null Foreign key References Students_Master(SID),
DOE Datetime not Null,
FWF Bit not null,
Grade char(1) Null check (Grade in ('O','A','B','C'))
)
go

Select * from Enrolment_Master


go

---Insert data (We can insert multiply data like fallow)


insert into Enrolment_Master values (40,1,'2024/02/20',0,'A')
insert into Enrolment_Master values (70,1,'2024/02/20',0,'O')
insert into Enrolment_Master values (10,2,'2024/02/20',1,'B')
insert into Enrolment_Master values (20,1,'2024/02/20',0,'A')
go
insert into Enrolment_Master values (50,3,'2024/03/11',1,'O')
insert into Enrolment_Master values (60,4,'2024/03/19',0,'B')
insert into Enrolment_Master values (40,5,'2024/04/23',1,'C')
insert into Enrolment_Master values (50,7,'2024/04/25',1,'B')
go
insert into Enrolment_Master values (60,4,'2024/03/27',0,'C')
insert into Enrolment_Master values (80,3,'2024/03/28',1,'B')
insert into Enrolment_Master values (80,4,'2024/04/29',0,'A')
insert into Enrolment_Master values (70,6,'2024/04/30',0,'O')

Note (40,1,'2024/02/20',0,'A') 40=courseName, 1=Id, DateTime ,0 or 1=Frue or Fails, O


or A,B,C= Grade

create database IBank


go

create table Account_Master


(
ACID int primary key,
Name varchar(40) not null,
Address varchar(50) not null,
BIRD char(3)not null, foreign key,
PID char(2) foreign key: not null,
Data of Opening datetime not null,
Clear Balance money null allowed,
Unclear Balance money null allowed,
Status char(1)
)
Go

use MIBCourse
go

/********************************************************************************
SPName: PreviouseMonthBankstatment
Author: Mohammad Ihsan
Date : Mar 2nd , 2021
Purpose

********************************************************************************/
create proc use_ProviouseMonthBankStatement
(
@SID int = 40
)
as
begin
print'......................................................................
print' Indian Bank '
print'List of Transactions from Mar 2nd to 20,2021 Report'
print'......................................................................'

end
go

use IBank
go

create proc usp_PreviuoseMonthBankSatetment


(
@acid int = 101
)
as
begin
print'......................................................................'
print' Indian Bank '
print'List of Transactions from Mar 2nd to 20,2021 Report'
print'......................................................................'
end
go

ddddd
create the follow tables for the banking database
create table customer
(customer_name varchar(15),
customer_street varchar(12) not null,
customer_city varchar(15) not null,
Primary key (customer_name));

Create table branch


(branch_name varchar(15),
branch _city varchar(15) not null,
assets number not null,
Primary key (branch_name));

Create table account


(account_number varchar(15),
branch _name varchar(15) not null,
balance number not null,
Primary key (account_number));

Create table loan


(loan_number varchar(15),
branch _name varchar(15) not null,
amount number not null,
Primary key (loan_number));
Create table depositor
(customer_name varchar(15) not null,
Amount_number varchar(15) not null,
Primary key (customer_name, account_number),
Foreign key (account_number) references account (account_name),
Foreign key (customer_name) references customer(customer_name));

Create table borrower


(customer_name varchar(15) not null,
Loan_number varchar(15) not null,
Primary key (customer_name, loan_number),
Foreign key (customert_name) references customer (customer_name),
Foreign key (loan_name) references loan(loan_name));

Insert the following data to the corresponding tables.


All customer data
Ihsan Main kabul
Karim Main kabul
Jamil North Zabul
Nadim University Kabul
Samir Park Herat

You might also like