sql-server-2012

Resetting Primary key without deleting truncating table

霸气de小男生 提交于 2019-12-05 21:48:29
I have a table with a primary key, now without any reason I don't know when I am inserting data it is being loaded like this Pk_Col Some_Other_Col 1 A 2 B 3 C 1002 D 1003 E 1901 F Is there any way I can reset my table like below, without deleting/ truncating the table? Pk_Col Some_Other_Col 1 A 2 B 3 C 4 D 5 E 6 F You can't update the IDENTITY column so DELETE/INSERT is the only way. You can reseed the IDENTITY column and recreate the data, like this: DBCC CHECKIDENT ('dbo.tbl',RESEED,0); INSERT INTO dbo.tbl (Some_Other_Col) SELECT Some_Other_Col FROM (DELETE FROM tbl OUTPUT deleted.*) d; That

Mainting Identity value across multiple tables

佐手、 提交于 2019-12-05 21:21:26
We have a situation where we have a column called Customer_Number in multiple tables. This column is identity column in all the tables, but is there a way that I can make this column unique among all the tables. for example if I add a row in table_one and identity column assigns it value 1 now if someone add another row in Customer_Number column of table_two , table_three or table_four it should be assigned 2. how can I do this, I have been reading online and it seems I have to create a table to keep record of the last generated value for any of the table and get MAX() of values from that

when to opt for caching in the Lookup component in SSIS

帅比萌擦擦* 提交于 2019-12-05 20:46:42
In SSIS Look up there are 3 types of Caches.. Full Partial and No cache. In our solution it has always been used the default one(Full).Is there any particular scenarios,where it can go for Partial cache/No Cache? In our solutions lockup tables are always small(example:-we have been looking at small tables to get the types or to get description).That might be the reason it has been configure in default(Full cache) mode? Please let me know the valuable suggestions and opinion. billinkc Let's cover the basics. Full Cache - prior to a data flow actually executing, all lookup components in full

compare s, t with ş, ţ in SQL Server

老子叫甜甜 提交于 2019-12-05 20:38:25
I followed this post How do I perform an accent insensitive compare (e with è, é, ê and ë) in SQL Server? but it doesn't help me with " ş ", " ţ " characters. This doesn't return anything if the city name is " iaşi " : SELECT * FROM City WHERE Name COLLATE Latin1_general_CI_AI LIKE '%iasi%' COLLATE Latin1_general_CI_AI This also doesn't return anything if the city name is " iaşi " (notice the foreign ş in the LIKE pattern): SELECT * FROM City WHERE Name COLLATE Latin1_general_CI_AI LIKE '%iaşi%' COLLATE Latin1_general_CI_AI I'm using SQL Server Management Studio 2012. My database and column

Return error message from stored procedure

霸气de小男生 提交于 2019-12-05 20:34:49
The question should be quite simple, but I can't figure out the answer nor why my stored procedure is not working. CREATE PROCEDURE spTest_Delete @ID int AS begin tran declare @err int declare @errMesage nvarchar(max) set @errMesage = '' set @err = 0 delete from Test where ID = @ID set @err = @@ERROR set @errMesage = ERROR_MESSAGE() if @err = 0 commit tran else begin RAISERROR(N'Could not delete !Error nr: %d. Message: %s', 1, 16, @err, @errMesage) rollback tran end This procedure runs ok, but in case of FK constraint on the delete statement it runs into an error (which is good) and I would

Ignore duplicate records in SSIS' OLE DB destination

旧城冷巷雨未停 提交于 2019-12-05 20:17:39
I'm using a OLE DB Destination to populate a table with value from a webservice. The package will be scheduled to run in the early AM for the prior day's activity. However, if this fails, the package can be executed manually. My concern is if the operator chooses a date range that over-laps existing data, the whole package will fail (verified). I would like it: INSERT the missing values (works as expected if no duplicates) ignore the duplicates; not cause the package to fail; raise an exception that can be captured by the windows application log (logged as a warning) collect the number of

fulltext index returning no results from pdf filestream

蓝咒 提交于 2019-12-05 20:16:15
I have a filestream table running on SQL Server 2012 on a Windows 8.1 x64 machine, which already have a few PDF and TXT files stored, so I decided to create a fulltext index to search through these files by using the following command: CREATE FULLTEXT CATALOG FileStreamFTSCatalog AS DEFAULT; CREATE FULLTEXT INDEX ON storage (FileName Language 1046, File TYPE COLUMN FileExtension Language 1046) KEY INDEX PK__storage__3214EC077DADCE3C ON FileStreamFTSCatalog WITH CHANGE_TRACKING AUTO; Then I sent these commands after reading some people having the same problem as me: EXEC sp_fulltext_service

SELECT query with multiple sub-queries for counts

跟風遠走 提交于 2019-12-05 19:07:45
I just wrote this query for a report. But I originally wrote it without the date range filter on every sub-query. But that didn't work. So I added it to each sub-query. And that worked, but I don't really like having to repeat it every time, is there syntax to do the same thing simpler? SELECT Count(r.id) AS cnt_total, (SELECT Count(r1.entity_id) FROM auto_reminders_members r1 WHERE r1.reminder_id = r.reminder_id AND r1.date_last_reminder BETWEEN CONVERT(DATETIME, '03/28/2013', 101) AND CONVERT(DATETIME, '03/28/2013' + ' 23:59:59.997 ', 101) AND r1.action = 'notnow') AS cnt_notnow, (SELECT

Creating Sub Directory via SQL INSERT using FileTable

蹲街弑〆低调 提交于 2019-12-05 19:05:17
问题 Previously, I requested how to create a directory within a FileTable without using File I/O APIs. I now want to create a subdirectory to the parent directory I just created. How do assign my parent during insert? It appears that parent_path_locator is a computed column. This creates my parent... INSERT INTO FileTable0 (name,is_directory,is_archive) VALUES ('Directory', 1, 0); How do I create a child directory to this parent in my FileTable? 回答1: This is what I ended up using to create a

SET a variable inside a CTE

纵饮孤独 提交于 2019-12-05 18:49:45
This is my first time I work with SQLServer 2012, and I have this code that it doesn't work: CREATE PROCEDURE ReadCodeBuffer @gint bigint, @pres tinyint, @level bigint, @quantity smallint, @xmlGenerated xml OUTPUT AS DECLARE @current_incremental bigint DECLARE @counter bigint DECLARE @xml XML -- Get current incremental. set @current_incremental = (SELECT INCREMENTAL FROM INCREMENTAL_TABLE WHERE GTIN = @gint AND PRESENTATION = @pres AND LEVEL = @level) -- with Numbers as ( select row_number() over(order by 1/0) as N from sys.all_objects as o1 cross join sys.all_objects as o2 ) SET @xml = (