-1

I have a piece of code I am not familiar with sql server, only oracle. Can someone tell me what this is doing? Thanks.

  • What is the @flowcontrol
  • what is set @flowcontrol = @@error? Why two @@?
  • Why is print twice? What does print do here?
  • What is raiseerror doing?

Use [ra8]
declare @flowcontrol integer
set @flowcontrol = @@error
if @flowcontrol = 0 
begin
  print ' '
  print 'create temp[nw] table'
  create table [dbo].[temp] ([feild] [varchar] (200) nulll
end
else
begin
  print ' '
  print ' '
  raiserror('raiseerror: create temp[nw] failed',12,1) with seterror
end
go
iminiki
  • 2,549
  • 12
  • 35
  • 45
  • @DavidG, thank for reply. If the question is terrible (while I don't think so), then it perhaps to be minused. By hardly can count my answer is terrible. So sorry, cannot get this kind of behavior. That reference link actually can be helpful to a newbie in SQL Server – Alexander Volok Sep 10 '19 at 15:05
  • 1
    It looks like you have several questions: [what is @@error?](https://stackoverflow.com/questions/6254286/error-in-sql-server-2005), [what does raiseerror do?](https://stackoverflow.com/questions/16170073/what-is-the-syntax-meaning-of-raiserror), [what is a variable in SQL Server?](https://stackoverflow.com/questions/6152001/how-to-set-variable-in-to-ms-sql-select) and "[Print statement in T-SQL](https://stackoverflow.com/questions/268384/print-statement-in-t-sql)"? – George Stocker Sep 10 '19 at 17:40

2 Answers2

2

@@VARIABLE - means it is a global variable maintained by SQL Server. Such variables represent information specific to the server or a current user session.

This wiki page has a listing of them and sample values: Global Variables in SQL Server

Alexander Volok
  • 5,630
  • 3
  • 17
  • 33
2

What is the @flowcontrol

  • @flowcontrol in this case is an integer variable (declared above)

what is set @flowcontrol = @@error? Why two @@?

  • the 2 @ means this is a special - or system - function

Why is print twice? What does print do here?

  • print is a function who write in the 'pipe' (messages parts in sql management studio). I think they are here to make some room in the messages to be more readable.

What is raiseerror doing?

  • Raiseerror, as its name sounds like - is raising an error.

Globally, this is creating an integer variable, checking errors on a previous instruction, if there are no error create a table, else raising an error.

EzLo
  • 13,780
  • 10
  • 33
  • 38
Cyril Rebreyend
  • 310
  • 2
  • 6