temp-tables

How to insert into a temp table the info given by RESTORE FILELISTONLY / HEADERONLY / VERIFYONLY

拈花ヽ惹草 提交于 2019-12-07 03:41:32
问题 How to insert the resultset given by the commands RESTORE FILELISTONLY RESTORE HEADERONLY RESTORE VERIFYONLY into an automatically generated temp table ? I would like to use a technique similar to (so the table is auto created, with all the columns matching the resultset's columns) SELECT * INTO #TempTable FROM (RESTORE FILELISTONLY FROM DISK = 'c:\Test\Test.bak') But this doesn't work. If I could populate a TempTable I could then be able to use the information contained in it in a following

Using temporary table in c#

£可爱£侵袭症+ 提交于 2019-12-07 01:46:56
问题 I read an excel sheet into a datagrid.From there , I have managed to read the grid's rows into a DataTable object.The DataTable object has data because when I make equal a grid's datasource to that table object , the grid is populated. My Problem : I want to use the table object and manipulate its values using SQL server,(i.e. I want to store it as a temporary table and manipulate it using SQL queries from within C# code and , I want it to return a different result inte a grid.(I don't know

How to create temp table from a dynamic query?

元气小坏坏 提交于 2019-12-06 16:57:15
问题 I want to create dynamic query for paging [ Main Motive ], here is my code: Alter proc proc_GetData ( @TableName varchar(500)='tblPropertyType', @PrimaryKey varchar(500)='Id', @Columns varchar(max)='PropertyType', @WhereCondition varchar(max)='', @RecsPerPage int =3, @Page int=1, @SortColumn varchar(500)='Id', @SortDirection Varchar(56)='asc' ) as DECLARE @SQL VARCHAR(MAX) DECLARE @DSQL VARCHAR(MAX) DECLARE @FirstRec int, @LastRec int SET @FirstRec = (@Page - 1) * @RecsPerPage SET @LastRec =

String or binary data would be truncated

混江龙づ霸主 提交于 2019-12-06 16:10:25
Msg 8152, Level 16, State 14, Line 60 String or binary data would be truncated. I am trying to insert into a temp table. This proc has been working through testing fine until yesterday. I got the truncate error, fixed a field and it began working. Today I ran it and I get the truncate error again. I tried setting all the fields in the insert equal to max and 8000 but to no avail. Is there some sort of data limit restriction to temp tables. I ran evaluations of all the max lengths of the input and all of them are within limit of the table construction. The Temp Table is pretty large but is in

Refactor SQLite Table by splitting it in two and link with foreign keys

北城余情 提交于 2019-12-06 09:57:01
问题 I'm working on a SQLite Database. The database is already filled, but I want to refactor it. Here is a sample of what I need to do: I currently have one table: CREATE TABLE Cars (ID INTEGER PRIMARY KEY, Name VARCHAR(32), TopSpeed FLOAT, EngineCap FLOAT); I want to split this into two tables: CREATE TABLE Vehicles (ID INTEGER PRIMARY KEY, Name VARCHAR(32), TopSpeed FLOAT); CREATE TABLE Cars (ID INTEGER PRIMARY KEY, VehicleID INTEGER CONSTRAINT FK_Cars REFERENCES [Vehicles](ID), EngineCap FLOAT

Temporary Tables Not Working in PHPMyAdmin

谁说我不能喝 提交于 2019-12-06 04:01:44
问题 I run this query CREATE TEMPORARY TABLE usercount SELECT * FROM users I get this message Your SQL query has been executed successfully ( Query took 0.1471 sec ) But when I try to access the newly created table using SELECT * FROM usercount I get this error #1146 - Table 'abc_site.usercount' doesn't exist Not sure why, I need to mention that I've did a good share of googling beforehand. My version of PHPMyAdmin is 3.5.2.2 and MySQL 5.5.27 回答1: PHPMyAdmin (or rather PHP) closes the database

SQL Server - Create temp table if doesn't exist

£可爱£侵袭症+ 提交于 2019-12-06 01:16:42
In my SQL Server 2012 environment, I've created a series of stored procedures that pass pre-existing temporary tables among themselves (I have tried different architectures here, but wasn't able to bypass this due to the nature of the requirements / procedures). What I'm trying to do is to, within a stored procedure check if a temporary table has already been created and, if not, to create it. My current SQL looks as follows: IF OBJECT_ID('tempdb..#MyTable') IS NULL CREATE TABLE #MyTable ( Col1 INT, Col2 VARCHAR(10) ... ); But when I try and run it when the table already exists , I get the

Normal table or global temp table?

[亡魂溺海] 提交于 2019-12-05 18:40:08
Me and another developer are discussing which type of table would be more appropriate for our task. It's basically going to be a cache that we're going to truncate at the end of the day. Personally, I don't see any reason to use anything other than a normal table for this, but he wants to use a global temp table. Are there any advantages to one or the other? Use a normal table in tempdb if this is just transient data that you can afford to lose on service restart or a user database if the data is not that transient. tempdb is slightly more efficient in terms of logging requirements. Global

Clustered index on temp table

可紊 提交于 2019-12-05 11:47:05
I'm trying to optimize a procedure that has code like the following: CREATE TABLE #t1 (c1 int, c2 varchar(20), c3(varchar(50)...) CREATE CLUSTERED INDEX ix_t1 ON #t1(c3) ON [PRIMARY] I wanted to improve that by moving the CLUSTERED index into the table declaration (more caching friendly), but c3 is not unique so this doesn't work: CREATE TABLE #t1 (c1 int, c2 varchar(20), c3 varchar(50)..., UNIQUE CLUSTERED (c3)) Is there a way to declare a clustered that is not unique in the temp table declaration? No there is not...the existence of the ability to define clustered as an option in table

DROP TABLE fails for temp table

旧街凉风 提交于 2019-12-05 10:43:46
I have a client application that creates a temp table, the performs a bulk insert into the temp table, then executes some SQL using the table before deleting it. Pseudo-code: open connection begin transaction CREATE TABLE #Temp ([Id] int NOT NULL) bulk insert 500 rows into #Temp UPDATE [OtherTable] SET [Status]=0 WHERE [Id] IN (SELECT [Id] FROM #Temp) AND [Group]=1 DELETE FROM #Temp WHERE [Id] IN (SELECT [Id] FROM [OtherTable] WHERE [Group]=1) INSERT INTO [OtherTable] ([Group], [Id]) SELECT 1 as [Group], [DocIden] FROM #Temp DROP TABLE #Temp COMMIT TRANSACTION CLOSE CONNECTION This is failing