Advertisement
Guest User

SQLtestSholdova

a guest
Mar 21st, 2018
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.13 KB | None | 0 0
  1. create table Users
  2. (
  3. Id bigint primary key identity(1,1)
  4. ,Name nvarchar(200)
  5. ,UserName Varchar(30)
  6. ,[Password] Varchar(30)
  7. ,CashAccountId Bigint
  8. ,ClientId Bigint
  9. )
  10.  
  11. insert into users values ('user3', 'username3', '12345678', 10000052, 12), ('user4',' username4', '21234567', 10000051, 13)
  12.  
  13. select *
  14. from users
  15.  
  16. create table Clients
  17. (
  18. Id bigint primary key identity(1,1)
  19. ,Name Nvarchar(200)
  20. ,[Type] Bit
  21. ,IdentificationNumber Varchar(36)
  22. ,[Address] Varchar(100)
  23. ,Tel Varchar(30)
  24. ,Mob Varchar(30)
  25. ,Email Varchar(30)
  26. ,Web Varchar(100)
  27. )
  28.  
  29. insert into clients values ('name1', 1, 1, 'treta makedonska brigada br.1','022000001','071000001','name1@yahoo.com', 'www.name1.com'),
  30. ('name2', 1, 2, 'treta makedonska brigada br.2','022000002','071000002','name2@yahoo.com', 'www.name2.com'),
  31. ('name3', 0, 3, 'treta makedonska brigada br.3','022000003','071000003','name3@yahoo.com', 'www.name3.com'),
  32. ('name4', 0, 4, 'treta makedonska brigada br.4','022000004','071000004','name4@yahoo.com', 'www.name4.com')
  33.  
  34. Select * from clients
  35.  
  36. create table Currencies
  37. (
  38. Currency Varchar(3) not null primary key
  39. ,Name Varchar(30)
  40. ,Symbol Nvarchar(5)
  41. ,[Image] Varbinary(8000)
  42. )
  43.  
  44.  
  45. insert into Currencies values
  46. ('65','Denari','MKD', null),
  47. ('1','Euros','Euro', null),
  48. ('1.2','Dolars','$', null)
  49.  
  50. Select * from Currencies
  51.  
  52. update Currencies
  53. set currency='61'
  54. where currency='65'
  55.  
  56. create table AccountClasses
  57. (
  58. Id Bigint primary key identity(1,1)
  59. ,Name Varchar(30)
  60. ,[Description] Nvarchar(100)
  61. ,[Type] Int unique check([Type] in (1,2,3,4))
  62. ,IsCashAccount as case when [Type] = 1 then 1 else 0 end
  63. ,IsCurrentAccount as case when [Type] = 2 then 1 else 0 end
  64. ,IsDepositAccount as case when [Type] = 3 then 1 else 0 end
  65. ,IsCreditAccount as case when [Type] = 4 then 1 else 0 end
  66. )
  67.  
  68. insert into AccountClasses values
  69. ('cash','cash account',1),
  70. ('Current','Current account',2),
  71. ('Deposit','Deposit account',3),
  72. ('Credit','Credit account',4)
  73.  
  74. select *
  75. from AccountClasses
  76.  
  77. create table AccountTypes
  78. (
  79. Id Bigint primary key identity(1,1)
  80. ,ClassId bigint foreign key references AccountClasses(Id)
  81. ,Name Varchar(30)
  82. ,[Description] Nvarchar(100)
  83. )
  84.  
  85.  
  86. insert into AccountTypes values
  87. (1,'cash account','cashe'),
  88. (2,'Current account','Current'),
  89. (3,'Deposit account','Deposit'),
  90. (4,'Credit account','Credit')
  91.  
  92. select *
  93. from AccountClasses AC Join AccountTypes AT on AC.Id=AT.Id
  94.  
  95. create table Accounts
  96. (
  97. Id Bigint primary key identity(1,1)
  98. ,TypeId bigint foreign key references AccountTypes(Id)
  99. ,AccountNumber Varchar(30) unique
  100. ,Currency varchar(3) foreign key references Currencies(Currency)
  101. ,ClientId bigint foreign key references Clients(Id)
  102. ,[Status] Varchar(1) check ([Status] in ('A','O','C'))
  103. ,Blocked bit
  104. ,Balance Decimal(19,2)
  105. ,OverdraftLimit Decimal(19,2)
  106. ,AmountOnHold Decimal(19,2)
  107. ,AvailableBalance as Balance+OverdraftLimit-AmountOnHold
  108. )
  109.  
  110.  
  111. create table TransactionTypes
  112. (
  113. Id Bigint primary key identity(1,1)
  114. ,Name Varchar(30)
  115. ,[Description] Nvarchar(100)
  116. ,AccountClassDebit bigint foreign key references AccountClasses(Id)
  117. ,AccountClassCredit bigint foreign key references AccountClasses(Id)
  118. ,ReflectsAmountOnHold bit default 0
  119. ,HasFee bit
  120. )
  121.  
  122.  
  123.  
  124.  
  125. create table Transactions
  126. (
  127. Id Bigint primary key identity(1,1)
  128. ,TransactionTypeId bigint foreign key references TransactionTypes(Id)
  129. ,UserId bigint foreign key references Users(Id)
  130. ,EntryDate Date default getdate()
  131. ,[Date] Date
  132. ,Currency varchar(3) foreign key references Currencies(Currency)
  133. ,AccountIdDebit Bigint foreign key references Accounts(Id)
  134. ,AccountIdCredit Bigint foreign key references Accounts(Id)
  135. ,Fee Decimal(19,2)
  136. ,Amount Decimal(19,2)
  137. ,[Description] Nvarchar(100)
  138. )
  139.  
  140. go
  141.  
  142. create table PostingEntries
  143. (
  144. Id Bigint primary key identity(1,1)
  145. ,TransactionId bigint foreign key references Transactions(Id)
  146. ,AccountId bigint foreign key references Accounts(Id)
  147. ,DebitCredit SmallInt check (DebitCredit in (-1,0,1))
  148. ,ContraAccountId bigint foreign key references Accounts(Id)
  149. ,Currency varchar(3) foreign key references Currencies(Currency)
  150. ,Amount Decimal(19,2)
  151. ,StatementNo int
  152. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement