SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 what is magic query in SQl
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

prasaditc55
Starting Member

8 Posts

Posted - 07/27/2012 :  02:59:37  Show Profile  Reply with Quote
Hi,

wat is magic query in sql with example

khtan
In (Som, Ni, Yak)

Singapore
16769 Posts

Posted - 07/27/2012 :  03:11:36  Show Profile  Reply with Quote
No idea. Never heard of that.


KH
Time is always against us

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
48012 Posts

Posted - 07/27/2012 :  03:17:11  Show Profile  Reply with Quote
where did you hear about it? in what context?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

robvolk
Most Valuable Yak

USA
15566 Posts

Posted - 07/27/2012 :  06:48:58  Show Profile  Visit robvolk's Homepage  Reply with Quote
I know we're not supposed to reveal all our tricks, but you can have these two:

SELECT Rabbit FROM Hat

INSERT Sleeve VALUES(Null)
Go to Top of Page

Transact Charlie
Flowing Fount of Yak Knowledge

United Kingdom
3448 Posts

Posted - 07/28/2012 :  13:46:39  Show Profile  Visit Transact Charlie's Homepage  Reply with Quote
well, any sufficiently advanced technology may be indistinguishable from magic but I doubt sql server qualified for that. Yet..........

If you are coming from an iterative background then the set based operations can seem magical but I doubt that's what you are after...

here's some..... advanced exploits of the engine that seem pretty magical:
http://beyondrelational.com/modules/2/blogs/70/posts/10865/quirky-update-in-sql-server.aspx
http://www.sqlservercentral.com/articles/T-SQL/62867/


Transact Charlie
Msg 3903.. The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION.
http://nosqlsolution.blogspot.co.uk/
Go to Top of Page

russell
Pyro-ma-ni-yak

USA
5037 Posts

Posted - 07/29/2012 :  18:24:32  Show Profile  Visit russell's Homepage  Reply with Quote
It is garbage/huge security hole that used to be built in with php befor version 5.
Go to Top of Page

prasaditc55
Starting Member

8 Posts

Posted - 07/29/2012 :  23:37:32  Show Profile  Reply with Quote
I heard this question in interview..
Go to Top of Page

Transact Charlie
Flowing Fount of Yak Knowledge

United Kingdom
3448 Posts

Posted - 07/30/2012 :  04:38:42  Show Profile  Visit Transact Charlie's Homepage  Reply with Quote
were they maybe talking about a product? There is this:
http://www.merlon.com/products_sqlmagic_info.html

Never used it or even heard of it. If that was interview question, be glad you didn't get the job.

Transact Charlie
Msg 3903.. The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION.
http://nosqlsolution.blogspot.co.uk/
Go to Top of Page

nigelrivett
Flowing Fount of Yak Knowledge

United Kingdom
3328 Posts

Posted - 07/30/2012 :  05:49:38  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
merge rather than magic?

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

SQLJames
Starting Member

28 Posts

Posted - 07/30/2012 :  10:32:25  Show Profile  Reply with Quote
Perhaps:

There are two tables Inserted and deleted in the SQL Server, which are popularly known as the Magic tables. These are not the physical tables but the SQL Server virtual tables usually used with the triggers to retrieve the inserted, deleted or updated rows.

From this link:http://beyondrelational.com/modules/17/interview-questions/238/interview-questions/7059/what-are-the-magic-tables-in-sql-server.aspx
Go to Top of Page

Transact Charlie
Flowing Fount of Yak Knowledge

United Kingdom
3448 Posts

Posted - 07/30/2012 :  10:40:23  Show Profile  Visit Transact Charlie's Homepage  Reply with Quote
well if someone asked me in an interview about magic tables I'd have to ask them what the hell they thought they were talking about. It would not be a good way to sell me on the company or development team!



Transact Charlie
Msg 3903.. The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION.
http://nosqlsolution.blogspot.co.uk/
Go to Top of Page

nigelrivett
Flowing Fount of Yak Knowledge

United Kingdom
3328 Posts

Posted - 07/30/2012 :  11:11:39  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
>> popularly known as the Magic tables
Possibly not that popularly known.

Googling there are some articles about this. I suspect this is someone trying to get a name accepted. Looks like some people have got together and referenced each others articles.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

xhostx
Constraint Violating Yak Guru

USA
261 Posts

Posted - 07/30/2012 :  11:31:01  Show Profile  Reply with Quote
Some unintentional Errors could lead to some magic queries :P

--------------------------
Get rich or die trying
--------------------------
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
48012 Posts

Posted - 07/30/2012 :  12:47:59  Show Profile  Reply with Quote
My guess is its called magic tables as it automatically assumes the structure of triggering table. But there's no official documentation I can find on this though.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

subhaoviya
Posting Yak Master

India
119 Posts

Posted - 07/31/2012 :  04:00:09  Show Profile  Reply with Quote

Magic tables are nothing but INSERTED, DELETED table scope level, These are not physical tables, only Internal tables.

This Magic table are used In SQL Server 6.5, 7.0 & 2000 versions with Triggers only.

But, In SQL Server 2005, 2008 & 2008 R2 Versions can use these Magic tables with Triggers and Non-Triggers also.

Using with Triggers:
If you have implemented any trigger for any Tables then,
1.Whenever you Insert a record on that table, That record will be there on INSERTED Magic table.
2.Whenever you Update the record on that table, That existing record will be there on DELETED Magic table and modified New data with be there in INSERTED Magic table.
3.Whenever you Delete the record on that table, That record will be there on DELETED Magic table Only.

These magic table are used inside the Triggers for tracking the data transaction.

Using Non-Triggers:
You can also use the Magic tables with Non-Trigger activities using OUTPUT Clause in SQL Server 2005, 2008 & 2008 R2 versions.

Go to Top of Page

khtan
In (Som, Ni, Yak)

Singapore
16769 Posts

Posted - 07/31/2012 :  04:14:44  Show Profile  Reply with Quote
if Magic tables = INSERTED / DELETED then Magic Query is query that uses INSERTED / DELETED.

That must be it. Yeah ! I got the job. Now how much are you offering me ?


KH
Time is always against us

Go to Top of Page

nigelrivett
Flowing Fount of Yak Knowledge

United Kingdom
3328 Posts

Posted - 07/31/2012 :  04:16:24  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
Where do you get the name "magic" for these tables?

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
48012 Posts

Posted - 07/31/2012 :  09:47:57  Show Profile  Reply with Quote
quote:
Originally posted by subhaoviya


Magic tables are nothing but INSERTED, DELETED table scope level, These are not physical tables, only Internal tables.

This Magic table are used In SQL Server 6.5, 7.0 & 2000 versions with Triggers only.

But, In SQL Server 2005, 2008 & 2008 R2 Versions can use these Magic tables with Triggers and Non-Triggers also.

Using with Triggers:
If you have implemented any trigger for any Tables then,
1.Whenever you Insert a record on that table, That record will be there on INSERTED Magic table.
2.Whenever you Update the record on that table, That existing record will be there on DELETED Magic table and modified New data with be there in INSERTED Magic table.
3.Whenever you Delete the record on that table, That record will be there on DELETED Magic table Only.

These magic table are used inside the Triggers for tracking the data transaction.

Using Non-Triggers:
You can also use the Magic tables with Non-Trigger activities using OUTPUT Clause in SQL Server 2005, 2008 & 2008 R2 versions.




Can you guide us to any official documentation which has a reference on this?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Transact Charlie
Flowing Fount of Yak Knowledge

United Kingdom
3448 Posts

Posted - 07/31/2012 :  10:18:37  Show Profile  Visit Transact Charlie's Homepage  Reply with Quote
there is no reference to Magic on BOL.

Transact Charlie
Msg 3903.. The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION.
http://nosqlsolution.blogspot.co.uk/
Go to Top of Page

DonAtWork
Flowing Fount of Yak Knowledge

2113 Posts

Posted - 07/31/2012 :  12:27:01  Show Profile  Reply with Quote
quote:
Originally posted by Transact Charlie

there is no reference to Magic on BOL.




Funny... I would have thought that Basketball On Line would SURELY mention Magic Johnson...










How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.14 seconds. Powered By: Snitz Forums 2000