Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 i need to excute a sql query is storing in data ro

Author  Topic 

anthor
Starting Member

14 Posts

Posted - 2012-01-21 : 14:14:03
i need to excute a sql query is storing in data row with T-SQL.
let me explain more detail.
i have saved all sql statement in a table name Tbl_Query,then T-SQL will excute all the Tbl_Query's Statement. below is my Tbl_Query Data Table.
ID(INT)/Query(VARCHAR(MAX)/Executed(BIT) is the Table Column.


ID Query Executed
1 SELECT * FROM TBL_CAR False
2 UPDATE TBL_CAR SET ID=2 WHERE ID=1 False
3 INSERT INTO TBL_CAR (ID) VALUES (10) False

how to do that?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-01-21 : 14:33:22
This is a very, very bad idea. You can achieve this via dynamic SQL and a loop, but I must ask WHY you'd want to do this. Why, oh why, oh why?!!

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

anthor
Starting Member

14 Posts

Posted - 2012-01-21 : 14:40:16
Errmm,i m using this method is because i m afaid that if i got 400 records to INSERT/UPDATE or delete, but unfortunately the client pc is occur problem or shut down. maybe he only inserted 200 records only, so they need to restore back the data and re-insert again.but this method we can detect that if 400 records are inserted we only execute the all queue to make sure they wont miss it.

p/s:afraid insert huge of record,but haven't inserted finish,the client pc is down.so the data only insert half.this is the problem

1 more question.

if i Passing 40000 records(maybe an array or Data Table) of integer IDs to select/update/delete records to stored procedure.after success passed.suddenly the client PC shut down or restarted.so the stored procedure or script still running on Server?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-01-21 : 14:57:59
My systems have hundreds and sometimes thousands of inserts per second. You should not code like this.

Do not pass 40000 integer IDs. Why would you be doing this?

The script will rollback if the SQL Server detected the disconnect.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2012-01-23 : 06:41:12
I have seen requests for this type of storage more than once. I fear that this is now being taught in "school".

http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspx
How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

For ultra basic questions, follow these links.
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

LoztInSpace
Aged Yak Warrior

940 Posts

Posted - 2012-01-24 : 01:24:11
Way to re-invent the stored procedure *and* transactions in one go!
Just do your work in a transaction. They're all or nothing - exactly what you are after.
Go to Top of Page
   

- Advertisement -