Pastebin
API
tools
faq
paste
Login
Sign up
Please fix the following errors:
New Paste
Syntax Highlighting
use dbeksamen drop table if exists timeregistration drop table if exists employeeprojects drop table if exists employee drop table if exists boss drop table if exists project drop table if exists customer create table customer ( id int identity primary key, customername varchar(50) ) create table project ( id int identity primary key, projectname varchar(50), projectstatus char(9) check(projectstatus in ('active','inactive')), customerid int not null references customer, fixedprice int, estimatedhours int, hourlyrate int ) create table boss ( id int identity primary key, name varchar(50) ) create table employee ( id int identity primary key, employeename varchar(50), bossid int not null references boss, timeoff int ) create table employeeprojects ( id int identity primary key, employeeid int not null references employee, projectid int not null references project ) create table timeregistration ( id int identity primary key, starttime datetime, endtime datetime, employeeid int not null references employee, projectid int not null references project, note varchar(500) ) go insert into customer values ('microsoft'), ('apple') insert into project values ('projectOne', 'active', 1, 5000, 10, null), ('projectTwo', 'inactive', 1, null, null, 500), ('projectThree', 'active', 2, 15000, 30, null), ('projectFour', 'active', 2, 6000, 11, null) insert into boss values ('jackson'), ('peterson') insert into employee values ('Ravn', 1, 2), ('Frost', 2, 5), ('Dennis', 1, 3) insert into employeeprojects values (1, 1), (1,2), (2,3), (3,4) insert into timeregistration values ((convert(datetime,'19-05-19 06:00:00 PM',5)), (convert(datetime,'19-05-19 08:00:00 PM',5)), 1, 1, '2 hours on projectOne'), ((convert(datetime,'13-05-19 09:00:00 PM',5)), (convert(datetime,'13-05-19 11:00:00 PM',5)), 1, 2, '2 hours on projectTwo'), ((convert(datetime,'13-05-19 09:00:00 PM',5)), (convert(datetime,'13-05-19 11:00:00 PM',5)), 2, 3, '2 hours on projectThree'), ((convert(datetime,'13-05-19 09:00:00 PM',5)), (convert(datetime,'13-05-19 11:00:00 PM',5)), 3, 4, '2 hours on projectFour') -- Ex2) --------------------------------------------------- go create index Employeetbl_timeoff on employee (timeoff asc) go select * from employee with(index(Employeetbl_timeoff)) create index Projecttbl_fixedprice on project (fixedprice asc) go select * from project with(index(Projecttbl_fixedprice)) -- Ex3) --------------------------------------------------- go select e.employeename from employee e join timeregistration t on e.id = t.employeeid join project p on t.projectid = p.id join customer c on c.id = p.customerid where c.customername = 'apple' --Ex4) ----------------------------------------------------- go create or alter trigger timeregistrationTrigger on timeregistration instead of insert as begin declare @daysbefore int declare @employeeonproject int declare @projectstatus char(9) select @daysbefore = DATEDIFF(day, GETDATE(), (select starttime from inserted)) if(@daysbefore <= -7) begin RAISERROR('Noget gik galt', 16, 1) return end select @employeeonproject = ep.employeeid from employeeprojects ep where ep.employeeid = (select employeeid from inserted) and ep.projectid = (select projectid from inserted) if(@employeeonproject IS NULL) begin RAISERROR('Noget gik galt', 16, 1) return end select @projectstatus = p.projectstatus from project p where p.id = (select projectid from inserted) if(@projectstatus = 'inactive') begin RAISERROR('Noget gik galt', 16, 1) return end insert into timeregistration values ( (select starttime from inserted), (select endtime from inserted), (select employeeid from inserted), (select projectid from inserted), (select note from inserted)) end --test til krav1) insert into timeregistration values ((convert(datetime,'14-05-19 09:00:00 PM',5)), (convert(datetime,'13-05-19 11:00:00 PM',5)), 1, 1, '2 hours on projectOne') --test til krav 2) insert into timeregistration values ((convert(datetime,'20-05-19 09:00:00 PM',5)), (convert(datetime,'13-05-19 11:00:00 PM',5)), 2, 1, '2 hours on projectOne') --test til krav 3) insert into timeregistration values ((convert(datetime,'20-05-19 09:00:00 PM',5)), (convert(datetime,'13-05-19 11:00:00 PM',5)), 1, 2, '2 hours on projectOne') --Ex5) ------------------------------------------------------------------ go create or alter function dbo.antalhverdageiMinutter(@aar int ,@maaned int) -- returnerer antal minutter i hverdage i den pågældende måned returns int as begin declare @res int declare @firstdayofmonth date = datefromparts(@aar,@maaned,1) declare @firstdayofnextmonth date = dateadd(mm,1,@firstdayofmonth) declare @lastdateofmonth date = dateadd(dd,-1,@firstdayofnextmonth) if day(@lastdateofmonth) = 28 set @res = 20 else if day(@lastdateofmonth) = 29 if datename(DW,@firstdayofmonth) in ('Saturday','Sunday') set @res = 20 else set @res = 21 else if day(@lastdateofmonth) = 30 if datename(DW,@firstdayofmonth) = 'Saturday' set @res = 20 else if datename(DW,@firstdayofmonth) in ('Friday','Sunday') set @res = 21 else set @res = 22 else if day(@lastdateofmonth) = 31 if datename(DW,@firstdayofmonth) in ('Friday','Saturday') set @res = 21 else if datename(DW,@firstdayofmonth) in ('Thursday','Sunday') set @res = 22 else set @res = 23 return 444*@res end go create or alter proc updatetimeoff @monthParameter int, @yearParameter int as begin declare @employeeid int declare @timeoff int declare @starttime datetime declare @endtime datetime declare @lastid int = 1 declare @minutes int = 0 declare @finalminutes int = 0 declare @numberOfRows int = 0 declare MY_CURSOR cursor local static forward_only for select e.id, e.timeoff, t.starttime, t.endtime from employee e join timeregistration t on t.employeeid = e.id open MY_CURSOR fetch next from MY_CURSOR into @employeeid, @timeoff, @starttime, @endtime while (@@FETCH_STATUS = 0) begin if MONTH(@starttime) = @monthParameter and YEAR(@starttime) = @yearParameter begin if @lastid = @employeeid begin if DATENAME(DW, @starttime) = 'Sunday' begin select @minutes += DATEDIFF(MINUTE, @starttime, @endtime) end else begin select @minutes += (DATEDIFF(MINUTE, @starttime, @endtime)) * 2 end end else begin update employee set timeoff += (@minutes - dbo.antalhverdageiMinutter(@yearParameter, @monthParameter)) where id = @lastid set @lastid += 1 set @minutes = 0 set @finalminutes = 0 if DATENAME(DW, @starttime) = 'Sunday' begin select @minutes += DATEDIFF(MINUTE, @starttime, @endtime) end else begin select @minutes += (DATEDIFF(MINUTE, @starttime, @endtime)) * 2 end end end fetch next from MY_CURSOR into @employeeid, @timeoff, @starttime, @endtime end close MY_CURSOR end exec updatetimeoff 5, 2019 select * from employee -- Ex8) --------------------------------- go exec sp_addlogin 'admin','123' exec sp_addlogin 'employee','123' exec sp_grantdbaccess 'admin' exec sp_grantdbaccess 'employee' exec sp_addrole 'administrators' exec sp_addrole 'employees' exec sp_addrolemember 'administrators','admin' exec sp_addrolemember 'employees','employee' grant select, insert, update, delete on database::dbeksamen to [admin] grant select, insert, update, delete on object::dbeksamen.dbo.timeregistration to [employee]
Optional Paste Settings
Category:
None
Cryptocurrency
Cybersecurity
Fixit
Food
Gaming
Haiku
Help
History
Housing
Jokes
Legal
Money
Movies
Music
Pets
Photo
Science
Software
Source Code
Spirit
Sports
Travel
TV
Writing
Tags:
Syntax Highlighting:
None
Bash
C
C#
C++
CSS
HTML
JSON
Java
JavaScript
Lua
Markdown (PRO members only)
Objective C
PHP
Perl
Python
Ruby
Swift
4CS
6502 ACME Cross Assembler
6502 Kick Assembler
6502 TASM/64TASS
ABAP
AIMMS
ALGOL 68
APT Sources
ARM
ASM (NASM)
ASP
ActionScript
ActionScript 3
Ada
Apache Log
AppleScript
Arduino
Asymptote
AutoIt
Autohotkey
Avisynth
Awk
BASCOM AVR
BNF
BOO
Bash
Basic4GL
Batch
BibTeX
Blitz Basic
Blitz3D
BlitzMax
BrainFuck
C
C (WinAPI)
C Intermediate Language
C for Macs
C#
C++
C++ (WinAPI)
C++ (with Qt extensions)
C: Loadrunner
CAD DCL
CAD Lisp
CFDG
CMake
COBOL
CSS
Ceylon
ChaiScript
Chapel
Clojure
Clone C
Clone C++
CoffeeScript
ColdFusion
Cuesheet
D
DCL
DCPU-16
DCS
DIV
DOT
Dart
Delphi
Delphi Prism (Oxygene)
Diff
E
ECMAScript
EPC
Easytrieve
Eiffel
Email
Erlang
Euphoria
F#
FO Language
Falcon
Filemaker
Formula One
Fortran
FreeBasic
FreeSWITCH
GAMBAS
GDB
GDScript
Game Maker
Genero
Genie
GetText
Go
Godot GLSL
Groovy
GwBasic
HQ9 Plus
HTML
HTML 5
Haskell
Haxe
HicEst
IDL
INI file
INTERCAL
IO
ISPF Panel Definition
Icon
Inno Script
J
JCL
JSON
Java
Java 5
JavaScript
Julia
KSP (Kontakt Script)
KiXtart
Kotlin
LDIF
LLVM
LOL Code
LScript
Latex
Liberty BASIC
Linden Scripting
Lisp
Loco Basic
Logtalk
Lotus Formulas
Lotus Script
Lua
M68000 Assembler
MIX Assembler
MK-61/52
MPASM
MXML
MagikSF
Make
MapBasic
Markdown (PRO members only)
MatLab
Mercury
MetaPost
Modula 2
Modula 3
Motorola 68000 HiSoft Dev
MySQL
Nagios
NetRexx
Nginx
Nim
NullSoft Installer
OCaml
OCaml Brief
Oberon 2
Objeck Programming Langua
Objective C
Octave
Open Object Rexx
OpenBSD PACKET FILTER
OpenGL Shading
Openoffice BASIC
Oracle 11
Oracle 8
Oz
PARI/GP
PCRE
PHP
PHP Brief
PL/I
PL/SQL
POV-Ray
ParaSail
Pascal
Pawn
Per
Perl
Perl 6
Phix
Pic 16
Pike
Pixel Bender
PostScript
PostgreSQL
PowerBuilder
PowerShell
ProFTPd
Progress
Prolog
Properties
ProvideX
Puppet
PureBasic
PyCon
Python
Python for S60
QBasic
QML
R
RBScript
REBOL
REG
RPM Spec
Racket
Rails
Rexx
Robots
Roff Manpage
Ruby
Ruby Gnuplot
Rust
SAS
SCL
SPARK
SPARQL
SQF
SQL
SSH Config
Scala
Scheme
Scilab
SdlBasic
Smalltalk
Smarty
StandardML
StoneScript
SuperCollider
Swift
SystemVerilog
T-SQL
TCL
TeXgraph
Tera Term
TypeScript
TypoScript
UPC
Unicon
UnrealScript
Urbi
VB.NET
VBScript
VHDL
VIM
Vala
Vedit
VeriLog
Visual Pro Log
VisualBasic
VisualFoxPro
WHOIS
WhiteSpace
Winbatch
XBasic
XML
XPP
Xojo
Xorg Config
YAML
YARA
Z80 Assembler
ZXBasic
autoconf
jQuery
mIRC
newLISP
q/kdb+
thinBasic
Paste Expiration:
Never
Burn after read
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Exposure:
Public
Unlisted
Private
Folder:
(members only)
Password
NEW
Enabled
Disabled
Burn after read
NEW
Paste Name / Title:
Create New Paste
Hello
Guest
Sign Up
or
Login
Sign in with Facebook
Sign in with Twitter
Sign in with Google
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Public Pastes
memtest 86 logg
1 hour ago | 229.83 KB
TLOZ Windwaker - Windfall Island - Virtual Pi...
4 hours ago | 1.57 KB
squar
10 hours ago | 0.10 KB
my-pus
10 hours ago | 0.09 KB
OoT rando seed 6/18
18 hours ago | 69.75 KB
Peter Thiel Dialog Society
20 hours ago | 23.72 KB
other seps
CSS | 21 hours ago | 0.15 KB
Check socradar.io for your FortiGate
PowerShell | 23 hours ago | 2.33 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the
Cookies Policy
.
OK, I Understand
Not a member of Pastebin yet?
Sign Up
, it unlocks many cool features!