Where to find tempdb logs in SQL Server? - sql

I'm currently using SQL Server 2014. In a stored procedure, I'm inserting data into a local temporary table (#TestTemporaryTable). I want to see the logs of data insertion into temp table, how can I fetch it from tempdb? And also, I want to know for how long these logs will exist?

You can examine the log records with the undocumented fn_dblog
eg
SELECT * FROM tempdb.sys.fn_dblog(NULL, NULL)

Related

How to check which stored procedure/function inserts/deletes/updates data to particular table with time stamp in SQL server

I want to check which stored procedure/function inserts/deletes/updates data to particular table with time stamp in SQL server.
I can get list of stored procedure(SP) and function that has table name in its body. but those Sp's or functions may or may not be calling the particular table
Please suggest.
I want to check which stored procedure/function inserts/deletes/updates data to particular table with time stamp in SQL server.
There is way to find tables which are modified ,but you cant get who did it
So below are the only ways
1.Enable Audit /extended events
2.Modify proc to insert data into some table with some checks like
tablename procname modifieddate

SQL Server bulk insert for large data set

I have 1 million rows of data in a file, I want to insert all the records into SQL Server. While inserting I am doing some comparison with existing data on the server, if the comparison satisfied I will update the existing records in the server or else I will insert the record from the file.
I'm currently doing this by looping from C#, which consume more than 3 hours to complete the work. Can anyone suggest idea to improve the performance?
Thanks,
Xavier.
Check if your database in Full or Simple recovery mode:
SELECT recovery_model_desc
FROM sys.databases
WHERE name = 'MyDataBase';
If database is SIMPLE recovery mode you can create a staging table right there. If it is in Full mode then better create Staging table in separate database with Simple model.
Use any BulkInsert operation/tool (for instance BCP, as already suggested)
Insert only those data from your staging table, which do not exist in your target table. (hope you know how to do it)

How To Get 'Create Table' script for a table or sp using vb6 with sql server 2000

I need the "create table... " statement for a particular table and stored procedure to recreate them in another database. Forget the backup and restore. I have to do it in vb6. Its the same thing you get when you copy the Table And paste it in query analyzer. Its sql server 2000
Edit: Now I Know it can be asked as 'How To Script Entire Database Through VB6'.
Take a look at this StackOverlow post which talks about the same. Although it is not VB6-specific, you should be able to apply this solution without a problem.
Essentially you create a stored procedure that will generate the CREATE TABLE statement for the given table. The stored procedure will examine the sysobjects table to build the SQL.
Your VB6 application can run the stored procedure on server 'A' fetching the CREATE TABLE SQL. Then connect to server 'B' and run that SQL to create the table on the other server.

Can many Users open a SP with a TempTable in it?

After a user is logged into his system and opens my progamm he can see data from a database depending on his WindowsUsername(I wrote a little stored procedure for that).
This Data comes from a query with a temporary Table (#temp). My question is now, if many users use this programm, after opening it they would all try to build the #temp Table within the stored procedure. Is that even possible?? Because if i try to build a tempTable with the same name the server gives me an error. Do i have to give dynamic TempTable names maybe according to the user who is logged in??? Or is there another better option?
MS-SQL Server
A local temp table (one #TableName) is per session/connection
Many users can not share a session/connection
So, a local temp table in a stored procedure is safe for may concurrent users
On the other hand you use a global temp table (##TableName) then it is visible to world+dog
From MSDN (my bold)
There are two types of temporary tables: local and global. Local temporary tables are visible only to their creators during the same connection to an instance of SQL Server as when the tables were first created or referenced. Local temporary tables are deleted after the user disconnects from the instance of SQL Server. Global temporary tables are visible to any user and any connection after they are created, and are deleted when all users that are referencing the table disconnect from the instance of SQL Server.
If it is a true temp table within a stored procedure (SP) then the temp table is created/only exists during the execution of the SP. If the sp is run multiple times by multiple users at the same time the temp table is created multiple times and stored in its own memory space for each user.
The results returned to each user will be unique and each copy of the temp table will not see the temp table from other sp calls.
If you are testing in a query window by creating the temp table twice then you will get an error.
To prove that the above works schedule the SP to run twice at the same time passing a different user id. You will get two different result sets.

fetch data from other server in create procedure

I have to create a procedure to fetch few values from database but I don't have access to write procedure on that server. So, I wanted to create that procedure on another server and fetch the values. I wanted to know if is it possible to create procedure to fetch values from any other server?.
Assume that in the target database you have read only access to fetch data. In that case you could
Create a database link from the database where you would be creating
stored procedure.
Read the data from target database using the database link (db link).
Once you are able to get the data from target database you could do any manipulation you would want to. For creating database link in sql server you could check this