Quantcast
Channel: SQL Server Database Engine forum
Viewing all 12963 articles
Browse latest View live

Table partitioning questions?

$
0
0

I have 4  tables which need to do partition. each table has one clustered index which is required & all tables have same column modified_on having datetime type except one.

My questions as follows

1) Do i need to create partition function & partition scheme  for each table?

2) Do i need to create 4 file groups for each table? is it good or bad?

3) what happens if i create 4 file groups & while creating partition scheme i can specify range value of date to each file group

(for ex:- FG1 for 2013, FG2 for 2014) same like for all 3 tables which has modified_on column.

4) what happens if i specify separate data file while creating file  groups then do partitioning.

5) sql has only 2 CPU's, is paritioning depend on CPU?

6) what are prerequisites & precautions for partitioning?

Please help me to clear my doubts.


November on TechNet: Calling All SQL DBE Gurus - Enlighten Us!

$
0
0

"An influential teacher, or popular expert"

 

Oh mighty reader, we need your enlightenment!

Only YOU can show us... the TRUE WAY to code!

 

Win the love and adoration of generations to come, by giving something back to those less awesome.

Show your technical prowess, and divine knowledge of your craft.

Teach us good code from bad.

Show us the way (or the work-around)

We can offer you the very best platform that you need to preach these good words.

Join us and lead this technical community in a whole new way, into a brighter future!

 

Become a TechNet Guru and you may find your own life also significantly enriched!

Win awards, interviews, invites, reviews, medals, friends, recognition points, high fives, hugs, smiles, and so much more!

All you have to do is add an article to TechNet Wiki from your own specialist field. Something that fits into one of the categories listed on the submissions page. Copy in your own blog posts, a forum solution, a white paper, or just something you had to solve for your own day's work today.

Drop us some nifty knowledge, or superb snippets, and become MICROSOFT TECHNOLOGY GURU OF THE MONTH!

This is an official Microsoft TechNet recognition, where people such as yourselves can truly get noticed!

 

HOW TO WIN

1) Please copy over your Microsoft technical solutions and revelations toTechNet Wiki.

2) Add a link to it on THIS WIKI COMPETITION PAGE (so we know you've contributed)

3) Every month, we will highlight your contributions, and select a "Guru of the Month" in each technology.

 

If you win, we will sing your praises in blogs and forums, similar to the weekly contributor awards. Once "on our radar" and making your mark, you will probably be interviewed for your greatness, and maybe eventually even invited into other inner TechNet/MSDN circles!

 

Winning this award in your favoured technology at least once is fast becoming a MUST HAVE!

 

Feel free to ask any questions below.

 

More about TechNet Guru Awards

Thanks in advance!
Pete Laker


#PEJL

Got any nice code? If you invest time in coding an elegant, novel or impressive answer on MSDN forums, why not copy it over to the one and onlyTechNet Wiki, for future generations to benefit from! You'll never get archived again!

If you are a member of any user groups, please make sure you list them in the Microsoft User Groups Portal. Microsoft are trying to help promote your groups, and collating them here is the first step.





#PEJL

Got any nice code? If you invest time in coding an elegant, novel or impressive answer on MSDN forums, why not copy it over to the one and onlyTechNet Wiki, for future generations to benefit from! You'll never get archived again!

If you are a member of any user groups, please make sure you list them in the Microsoft User Groups Portal. Microsoft are trying to help promote your groups, and collating them here is the first step.

Suspected problem with identity seed on SQL Server 2012 Standard

$
0
0

SQL Server version 11.0.3128. I have an automated process (job, stored procedure) that inserts DMV data into database tables every half hour. It has run without incident for well over a month. On Nov. 14, the 19:20 run failed with 46 instances of "Violation of primary key constraint ... cannot insert duplicate key ..." into one of the tables. The key of the table is an identity, type integer, start 1 increment 1, values attempted for insert 317211 - 317256. The 19:50 run ran fine.

Looking at the table I can see rows with the identity column, values 317211 - 317256, timestamped at 18:50. Looks like the error message is valid, the identity key values attempted for insert were already used.

There is a daily job running at 19:00 that takes 5 or 6 minutes, it runs dbcc checkdb, reorgs all indexes, and updates all statistics, for many databases.

Did I happen across a rarely-occuring bug?

slow query

$
0
0

I have 2 identical database, replicated. the table structure, indexes, text indexes, and data are identical. both servers are running the same exact version of sql server 

Microsoft SQL Server 2008 (SP3) - 10.0.5512.0 (X64)   Aug 22 2012 19:25:47   Copyright (c) 1988-2008 Microsoft Corporation  Enterprise Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1) 

on one server the query (a complicated search on a dozen optional fields in various tables including several text strings - the text search improvements of sql2012 will allow me to simplify the text searching, but that is in the future)

the query finishes in a few seconds, on the other server it is taking minutes. 

I have narrowed the problem to a left join to a table with 83,000 rows which looks things up via the primary clustered index

I cannot see why this should has any serious effect on performance. I have rebuilt the test indexes and done a dbreindex on the offending table

am am including the creation script for the FK table followed by the query. the query is from the SP, with the parameters changed to a declare and set to provide the passed parameters, the commented out sections have no performance effect. it is the last left join causing the problem.

USE [recordings]
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[broadcast_barcodes](
[broadcast_archive_num] [int] NOT NULL,
[barcode] [char](10) NOT NULL,
[rowguid] [uniqueidentifier] ROWGUIDCOL  NOT NULL,
 CONSTRAINT [PK_broadcast_barcodes] PRIMARY KEY CLUSTERED 
(
[broadcast_archive_num] ASC,
[barcode] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO


USE [recordings]
CREATE UNIQUE NONCLUSTERED INDEX [Index_broadcast_barcodes_rg] ON [dbo].[broadcast_barcodes] 
(
[rowguid] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [index]
GO


USE [recordings]
CREATE UNIQUE NONCLUSTERED INDEX [IX_broadcast_barcodes] ON [dbo].[broadcast_barcodes] 
(
[barcode] ASC,
[broadcast_archive_num] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [index]
GO

ALTER TABLE [dbo].[broadcast_barcodes]  WITH NOCHECK ADD  CONSTRAINT [FK_broadcast_barcodes_barcodes] FOREIGN KEY([barcode])
REFERENCES [dbo].[barcodes] ([barcode])
NOT FOR REPLICATION 
GO

ALTER TABLE [dbo].[broadcast_barcodes] CHECK CONSTRAINT [FK_broadcast_barcodes_barcodes]
GO

ALTER TABLE [dbo].[broadcast_barcodes]  WITH CHECK ADD  CONSTRAINT [FK_broadcast_barcodes_broadcast_barcodes] FOREIGN KEY([broadcast_archive_num])
REFERENCES [dbo].[broadcasts] ([broadcast_archive_num])
GO

ALTER TABLE [dbo].[broadcast_barcodes] CHECK CONSTRAINT [FK_broadcast_barcodes_broadcast_barcodes]
GO

ALTER TABLE [dbo].[broadcast_barcodes] ADD  CONSTRAINT [DF_broadcast_barcodes_rowguid]  DEFAULT (newsequentialid()) FOR [rowguid]
GO

=============================================================================

declare @subnet varchar(20),@text nvarchar(50),@search_type tinyint
 ,@channel tinyint,@from_date date,@to_date date,@broadcast_items xml
 ,@job tinyint,@workers xml,@has_digital_media bit
 ,@inc_spokesman bit,@inc_nonspokesman bit,@people xml,@topic xml

BEGIN
set @subnet=N'192.168.4.0'
set @text=N'משפט ג''ון' set @search_type=1 set @inc_spokesman=1 set @inc_nonspokesman=1
 
 /*
 exec dbo.item_adv_search
      @subnet='192.168.4.0',
      @text='כותרת',
      @search_type=1,
      @channel = null,
      @from_date = '2013-02-01',
      @to_date = '2013-02-28',
      @broadcast_items=null,--'<root><r item="3"/></root>', -- or null
      @job = null,
      @workers = null,--'<root><r worker="3"/></root>', -- or null
      @has_digital_media=null,
      @inc_spokesman='1',
      @inc_nonspokesman='1',
      @people = null,--'<root><r person="3"/></root>', -- or null
      @topic = null--'<root><r topic="3"/></root>' -- or null
 */
 declare @idoc int
 declare @bitems table(item int)
 declare @emps table (emp int)
 declare @guests table(guest int)
 declare @topics table(subjects tinyint)
 
 declare @res table
 (broadcast_archive_num int,item_archive_num int,sort_order int,
  broadcast_date date,broadcast_time time(0),
  channel_code tinyint,channel_desc nvarchar(20),
  broadcast_item_name nvarchar(70),item_title nvarchar(200),item_desc nvarchar(max),
  Spokesman_str nvarchar(100), Reference_str nvarchar(100),
  digital_media_url varchar(100),file_code int,
  barcode char(10),lush_broadcast_item_code int,file_cnt smallint,play_cnt smallint)
     
 -- load chosen broadcast_items
 --if @broadcast_items is not null
 --   begin
-- EXEC sp_xml_preparedocument @idoc OUTPUT, @broadcast_items  
--  INSERT INTO @bitems(item)
          
--SELECT  item
--FROM       OPENXML (@idoc, '/root/r',1)
--WITH (item int)
-- exec sp_xml_removedocument @idoc 
 --   end
 --    -- load chosen workers
 --if @workers is not null
 --   begin
-- EXEC sp_xml_preparedocument @idoc OUTPUT, @workers
--  INSERT INTO @emps(emp)
          
--SELECT  worker
--FROM       OPENXML (@idoc, '/root/r',1)
--WITH (worker int)
-- exec sp_xml_removedocument @idoc 
 --   end
 --   -- load chosen people
 --if @people is not null
 --   begin
-- EXEC sp_xml_preparedocument @idoc OUTPUT, @people
--  INSERT INTO @guests(guest)
          
--SELECT  person
--FROM       OPENXML (@idoc, '/root/r',1)
--WITH (person int)
-- exec sp_xml_removedocument @idoc 
 --   end
    
 --     -- load chosen topics
 --if @topic is not null
 --   begin
-- EXEC sp_xml_preparedocument @idoc OUTPUT, @topic
--  INSERT INTO @topics(subjects)
          
--SELECT  topic
--FROM       OPENXML (@idoc, '/root/r',1)
--WITH (topic int)
-- exec sp_xml_removedocument @idoc 
 --   end
    
 declare @junk nvarchar(20)='rwcwcqw978fsadf7qwer'
 declare @word1 nvarchar(25)=@junk
 declare @word2 nvarchar(25)=@junk
 declare @word3 nvarchar(25)=@junk
 declare @word4 nvarchar(25)=@junk
 declare @word5 nvarchar(25)=@junk
 declare @word1a nvarchar(25)=@junk
 declare @word2a nvarchar(25)=@junk
 declare @word3a nvarchar(25)=@junk
 declare @word4a nvarchar(25)=@junk
 declare @word5a nvarchar(25)=@junk
 declare @word1b nvarchar(25)=@junk
 declare @word2b nvarchar(25)=@junk
 declare @word3b nvarchar(25)=@junk
 declare @word4b nvarchar(25)=@junk
 declare @word5b nvarchar(25)=@junk
 declare @word1c nvarchar(25)=@junk
 declare @word2c nvarchar(25)=@junk
 declare @word3c nvarchar(25)=@junk
 declare @word4c nvarchar(25)=@junk
 declare @word5c nvarchar(25)=@junk
 declare @word1d nvarchar(25)=@junk
 declare @word2d nvarchar(25)=@junk
 declare @word3d nvarchar(25)=@junk
 declare @word4d nvarchar(25)=@junk
 declare @word5d nvarchar(25)=@junk
 declare @word1e nvarchar(25)=@junk
 declare @word2e nvarchar(25)=@junk
 declare @word3e nvarchar(25)=@junk
 declare @word4e nvarchar(25)=@junk
 declare @word5e nvarchar(25)=@junk
 declare @word1f nvarchar(25)=@junk
 declare @word2f nvarchar(25)=@junk
 declare @word3f nvarchar(25)=@junk
 declare @word4f nvarchar(25)=@junk
 declare @word5f nvarchar(25)=@junk
 
 
 declare @loc tinyint,@copy_text nvarchar(70)=dbo.trim(@text)
 
 -- type 2 (use phrase as string)
 
 declare @ftext nvarchar(60) ='"'+@text+'"'
 
   -- type 1 (break into separate words)
   
 set @copy_text=replace(@copy_text,'"','""')
 set @copy_text=replace(@copy_text,'''','''''')
 
 if isnull(@copy_text,'')='' goto done_word_break
 
 set @loc =charindex(' ',@copy_text)
 if @loc=0
begin
set @word1=@copy_text
set @word1a='"'+@copy_text+'*"'
goto done_word_break
end
 else begin
set @word1=left(@copy_text,@loc-1)
set @word1a='"'+left(@copy_text,@loc-1)+'*"'
set @copy_text=ltrim(substring(@copy_text,@loc+1,100))
end
 
 set @loc =charindex(' ',@copy_text)
 if @loc=0 
begin
set @word2=@copy_text
set @word2a='"'+@copy_text+'*"'
goto done_word_break
end
 else begin
set @word2=left(@copy_text,@loc-1)
set @word2a='"'+left(@copy_text,@loc-1)+'*"'
set @copy_text=ltrim(substring(@copy_text,@loc+1,100))
end
 
 set @loc =charindex(' ',@copy_text)
 if @loc=0
begin
set @word3=@copy_text
set @word3a='"'+@copy_text+'*"'
goto done_word_break
end
 else begin
set @word3=left(@copy_text,@loc-1)
set @word3a='"'+left(@copy_text,@loc-1)+'*"'
set @copy_text=ltrim(substring(@copy_text,@loc+1,100))
end

 set @loc =charindex(' ',@copy_text)
 if @loc=0 
begin
set @word4=@copy_text
set @word4a='"'+@copy_text+'*"'
goto done_word_break
end
 else begin
set @word4=left(@copy_text,@loc-1)
set @word4a='"'+left(@copy_text,@loc-1)+'*"'
set @copy_text=ltrim(substring(@copy_text,@loc+1,100))
end
 
 set @loc =charindex(' ',@copy_text)
 if @loc=0
begin
set @word5=@copy_text
set @word5a='"'+@copy_text+'*"'
goto done_word_break
end
 else begin
set @word5=left(@copy_text,@loc-1)
set @word5a='"'+left(@copy_text,@loc-1)+'*"'
set @copy_text=ltrim(substring(@copy_text,@loc+1,100))
end

 
done_word_break:
 set @word1b='ב'+@word1
 set @word1c='ה'+@word1
 set @word1d='ו'+@word1
 set @word1e='ל'+@word1
 set @word1f='מ'+@word1
 set @word2b='ב'+@word2
 set @word2c='ה'+@word2
 set @word2d='ו'+@word2
 set @word2e='ל'+@word2
 set @word2f='מ'+@word2
 set @word3b='ב'+@word3
 set @word3c='ה'+@word3
 set @word3d='ו'+@word3
 set @word3e='ל'+@word3
 set @word3f='מ'+@word3
 set @word4b='ב'+@word4
 set @word4c='ה'+@word4
 set @word4d='ו'+@word4
 set @word4e='ל'+@word4
 set @word4f='מ'+@word4
 set @word5b='ב'+@word5
 set @word5c='ה'+@word5
 set @word5d='ו'+@word5
 set @word5e='ל'+@word5
 set @word5f='מ'+@word5
 
 set @from_date=isnull(@from_date,'1900-1-1')
 set @to_date=isnull(@to_date,'2078-12-31')
 

--insert into @res 
-- (broadcast_archive_num ,item_archive_num ,sort_order ,
--  broadcast_date ,broadcast_time ,
--  channel_code ,channel_desc ,
--  broadcast_item_name ,item_title ,item_desc ,
--  Spokesman_str , Reference_str ,
--  digital_media_url,
--  barcode ,lush_broadcast_item_code,
--  file_cnt,play_cnt,file_code )
  
 select top 101 dbo.broadcasts.broadcast_archive_num
      , dbo.items.item_archive_num,items.sort_order
      , dbo.broadcasts.broadcast_date,dbo.broadcasts.broadcast_time
      ,broadcast_items.channel_code,dbo.adm_channels.channel_desc
      ,isnull(broadcast_items.broadcast_item_name,dbo.broadcasts.program_title) as broadcast_item_name
      --,dbo.items.item_title,dbo.items.item_desc
      --,dbo.get_item_people_str(dbo.items.item_archive_num,'1') as Spokesman_str
      --,dbo.get_item_people_str(dbo.items.item_archive_num,'0') as Reference_str
      --,dbo.get_digital_media_url(@subnet,null,
      --          dbo.get_item_0(broadcasts.broadcast_archive_num),null,null) as digital_media_url
      --,dbo.barcodes.barcode,dbo.broadcasts.lush_broadcast_item_code
      --,cnts.file_cnt,cnts.play_cnt
      --,isnull(archive_files.file_code,
      -- (select top 1 file_code
      --    from dbo.archive_files
      --    where item_archive_num=  dbo.get_item_0(broadcasts.broadcast_archive_num)
      --     and is_primary ='1'  )) as file_code
 from dbo.items inner join dbo.broadcasts
   on dbo.broadcasts.broadcast_archive_num=dbo.items.broadcast_archive_num 
   left join
      dbo.broadcast_items
   on broadcast_items.broadcast_item_code=dbo.broadcasts.lush_broadcast_item_code left join 
      dbo.adm_channels
   on dbo.adm_channels.channel_code=broadcast_items.channel_code 
   left join
       dbo.broadcast_barcodes
   on dbo.broadcast_barcodes.broadcast_archive_num=dbo.broadcasts.broadcast_archive_num
   --   left join dbo.barcodes
   --on dbo.barcodes.barcode=dbo.broadcast_barcodes.barcode
   --left join dbo.archive_files
   --on archive_files.item_archive_num=items.item_archive_num
   --   and is_primary='1'
   --left join dbo.digital_files
   --  on digital_files.file_code=archive_files.file_code
   --left join dbo.adm_code_media_file_types
   --  on dbo.adm_code_media_file_types.media_file_type_code=digital_files.media_file_type_code
   --  cross apply 
   --  (select file_cnt=count(*),play_cnt=isnull(sum(convert(tinyint,can_play)),0)
   --    from dbo.archive_files
--  inner join dbo.digital_files
-- on digital_files.file_code=archive_files.file_code
--  inner join dbo.adm_code_media_file_types
-- on dbo.adm_code_media_file_types.media_file_type_code=digital_files.media_file_type_code
-- where archive_files.item_archive_num in 
--  (items.item_archive_num,dbo.get_item_0(items.broadcast_archive_num) )) cnts
    
where items.net_code=2 and
      --broadcasts.broadcast_date between @from_date and @to_date and
      --(broadcast_items.channel_code =@channel or @channel is null) and
      --(@has_digital_media is null or 
      -- (@has_digital_media= dbo.adm_code_media_file_types.can_play))  and
      --(broadcast_items.broadcast_item_code in (select item from @bitems) or 
      --  @broadcast_items is null) and
      --(@workers is null or items.item_archive_num in (select item_archive_num from item_workers
      --                                          where (job_code =@job or @job is null)
      --                                            and worker_code in
      --                                              (select emp from @emps))) and
      --(@topic is null or items.item_archive_num in (select item_archive_num from item_topics
      --                                               where topic_code in
      --                                              (select subjects from @topics))) and
      --(@people is null or 
      --  items.item_archive_num in (select item_archive_num from item_people
      --                              where (( dbo.item_people.is_spokesman='1' and @inc_spokesman='1')
      --                                       or 
      --                                     ( dbo.item_people.is_spokesman='0' and @inc_nonspokesman='1'))
      --                                            and person_code in
      --                                              (select guest from @guests))) and
     (( @search_type=1 
          and (@word1=@junk
              or contains(item_title, @word1a)
              or contains(item_title, @word1b)
              or contains(item_title, @word1c)
              or contains(item_title, @word1d)
              or contains(item_title, @word1e)
              or contains(item_title, @word1f)
              or contains(item_desc , @word1a)
              or contains(item_desc , @word1b)
              or contains(item_desc , @word1c)
              or contains(item_desc , @word1d)
              or contains(item_desc , @word1e)
              or contains(item_desc , @word1f))
          and (@word2=@junk
              
              or contains(item_title, @word2a)
              or contains(item_title, @word2b)
              or contains(item_title, @word2c)
              or contains(item_title, @word2d)
              or contains(item_title, @word2e)
              or contains(item_title, @word2f)
              or contains(item_desc , @word2a)
              or contains(item_desc , @word2b)
              or contains(item_desc , @word2c)
              or contains(item_desc , @word2d)
              or contains(item_desc , @word2e)
              or contains(item_desc , @word2f))
          and (@word3=@junk
             
              or contains(item_title, @word3a)
              or contains(item_title, @word3b)
              or contains(item_title, @word3c)
              or contains(item_title, @word3d)
              or contains(item_title, @word3e)
              or contains(item_title, @word3f)
              or contains(item_desc , @word3a)
              or contains(item_desc , @word3b)
              or contains(item_desc , @word3c)
              or contains(item_desc , @word3d)
              or contains(item_desc , @word3e)
              or contains(item_desc , @word3f))
          and (@word4=@junk
              
              or contains(item_title, @word4a)
              or contains(item_title, @word4b)
              or contains(item_title, @word4c)
              or contains(item_title, @word4d)
              or contains(item_title, @word4e)
              or contains(item_title, @word4f)
              or contains(item_desc , @word4a)
              or contains(item_desc , @word4b)
              or contains(item_desc , @word4c)
              or contains(item_desc , @word4d)
              or contains(item_desc , @word4e)
              or contains(item_desc , @word4f))
          and (@word5=@junk
              
              or contains(item_title, @word5a)
              or contains(item_title, @word5b)
              or contains(item_title, @word5c)
              or contains(item_title, @word5d)
              or contains(item_title, @word5e)
              or contains(item_title, @word5f)
              or contains(item_desc , @word5a)
              or contains(item_desc , @word5b)
              or contains(item_desc , @word5c)
              or contains(item_desc , @word5d)
              or contains(item_desc , @word5e)
              or contains(item_desc , @word5f)))
              
  or
      (@search_type=2 
         and (contains(item_title, @ftext)
              or contains(item_desc , @ftext)))
     )
option(recompile)

--if isnull(@text,'')<>''
--insert into @res 
--(broadcast_archive_num ,item_archive_num ,sort_order ,
-- broadcast_date ,broadcast_time ,
-- channel_code ,channel_desc ,
-- broadcast_item_name ,item_title ,item_desc ,
-- Spokesman_str , Reference_str ,
-- digital_media_url,
-- barcode ,lush_broadcast_item_code,
-- file_cnt,play_cnt,file_code )
  
-- select top 101 dbo.broadcasts.broadcast_archive_num
--      , dbo.items.item_archive_num,items.sort_order
--      , dbo.broadcasts.broadcast_date,dbo.broadcasts.broadcast_time
--      ,broadcast_items.channel_code,dbo.adm_channels.channel_desc
--      ,isnull(broadcast_items.broadcast_item_name,dbo.broadcasts.program_title) as broadcast_item_name
--      ,dbo.items.item_title,dbo.items.item_desc
--      ,dbo.get_item_people_str(dbo.items.item_archive_num,'1') as Spokesman_str
--      ,dbo.get_item_people_str(dbo.items.item_archive_num,'0') as Reference_str
--      ,dbo.get_digital_media_url(@subnet,null,
--                dbo.get_item_0(broadcasts.broadcast_archive_num),null,null) as digital_media_url
--      ,dbo.barcodes.barcode,dbo.broadcasts.lush_broadcast_item_code
--      ,cnts.file_cnt,cnts.play_cnt,archive_files.file_code
-- from dbo.items inner join dbo.broadcasts
--   on dbo.broadcasts.broadcast_archive_num=dbo.items.broadcast_archive_num left join
--      dbo.broadcast_items
--   on broadcast_items.broadcast_item_code=dbo.broadcasts.lush_broadcast_item_code left join 
--      dbo.adm_channels
--   on dbo.adm_channels.channel_code=broadcast_items.channel_code left join
--       dbo.broadcast_barcodes
--   on dbo.broadcast_barcodes.broadcast_archive_num=dbo.broadcasts.broadcast_archive_num
--      left join dbo.barcodes
--   on dbo.barcodes.barcode=dbo.broadcast_barcodes.barcode
--   left join dbo.archive_files
--   on archive_files.item_archive_num=items.item_archive_num
--      and is_primary='1'
--   left join dbo.digital_files
--     on digital_files.file_code=archive_files.file_code
--   left join dbo.adm_code_media_file_types
--     on dbo.adm_code_media_file_types.media_file_type_code=digital_files.media_file_type_code
--     cross apply 
--     (select file_cnt=count(*),play_cnt=isnull(sum(convert(tinyint,can_play)),0)
--       from dbo.archive_files
--  inner join dbo.digital_files
--on digital_files.file_code=archive_files.file_code
--  inner join dbo.adm_code_media_file_types
--on dbo.adm_code_media_file_types.media_file_type_code=digital_files.media_file_type_code
--where archive_files.item_archive_num in 
-- (items.item_archive_num,dbo.get_item_0(items.broadcast_archive_num) )) cnts
    
--where items.net_code=2 and
--      broadcasts.broadcast_date between @from_date and @to_date and
--      (broadcast_items.channel_code =@channel or @channel is null) and
--      (@has_digital_media is null or 
--       (@has_digital_media= dbo.adm_code_media_file_types.can_play))  and
--      (broadcast_items.broadcast_item_code in (select item from @bitems) or 
--        @broadcast_items is null) and
--      (@workers is null or items.item_archive_num in (select item_archive_num from item_workers
--                                                where (job_code =@job or @job is null)
--                                                  and worker_code in
--                                                    (select emp from @emps))) and
--      (@topic is null or items.item_archive_num in (select item_archive_num from item_topics
--                                                     where topic_code in
--                                                    (select subjects from @topics))) and
--      (@people is null or 
--        items.item_archive_num in (select item_archive_num from item_people
--                                    where (( dbo.item_people.is_spokesman='1' and @inc_spokesman='1')
--                                             or 
--                                           ( dbo.item_people.is_spokesman='0' and @inc_nonspokesman='1'))
--                                                  and person_code in
--                                                    (select guest from @guests))) and
--     (( @search_type=1 
--          and (@word1=@junk
--              or dbo.broadcasts.program_title like '%'+replace(@word1,'''''','''')+'%')
--          and (@word2=@junk
--              or dbo.broadcasts.program_title like '%'+replace(@word2,'''''','''')+'%')
--          and (@word3=@junk
--              or dbo.broadcasts.program_title like '%'+replace(@word3,'''''','''')+'%')
--          and (@word4=@junk
--              or dbo.broadcasts.program_title like '%'+replace(@word4,'''''','''')+'%')
--          and (@word5=@junk
--              or dbo.broadcasts.program_title like '%'+replace(@word5,'''''','''')+'%'))
              
--  or
--      (@search_type=2 
--         and dbo.broadcasts.program_title ='%'+@text+'%')
--     )
--option(recompile)




--select item_list='item_list',* from @res

--select 'rows' as [rows],@@rowcount as row_cnt

--select 'topic_cnt' as topic_cnt,item_topics.topic_code,topic_desc,count(*) as cnt
--  from @res r inner join item_topics
--    on item_topics.item_archive_num=r.item_archive_num inner join
--    adm_code_topics 
--    on adm_code_topics.topic_code=item_topics.topic_code
--  group by item_topics.topic_code,topic_desc,adm_code_topics.sort_order
--  order by count(*) desc,adm_code_topics.sort_order asc
END


???

sp_execute sql calling stored procedure fails during insert to table but calling procedure in SSMS works fine

$
0
0

I have a 3rd party system that uses sp_executesql under the covers (figured that out with profiler).  I have a procedure that works fine when calling it directly in SSMS, but when I call it via the same statement that this 3rd party system issuing, I get an error.

The procedure is using TRY/CATCH, so I can see the error message its returning, but why?

In both cases, I am executing both statements in SSMS, the one using execute works fine, but calling sp_executesql fails.  The error message indicates its trying to insert a null value into a table, for which it should have already had, or least that's the case with calling the procedure directly (execute procedure_name...)

Transaction Log Reuse

$
0
0

Hi~ My databases are in simple mode. And I find those log are very large about 50GB.

how can I know when their log are reusing ? or it will keep growing?

thats strange everytime I shink it,i grows to a certain size and stop grow anymore.

Migration Prerequisites from 2008 to 2012 sql server

$
0
0

hi,

what are the Prerequisites for migration from sql server 2008 to sql server 2012 server, and what are steps i can follow here.


SQL server job failed.

$
0
0

Hi all,

I am calling a store procedure through my job. (This store procedure again calls below given three stored procedure) 

EXEC [DMReportingNew].[dbo].Load_DMReport;

Exec [EPMReporting].[dbo].[EXECUTE_ALL_SP];

EXEC [DMReportingNew].[dbo].[EXECUTE_ALL_SP];

Suppose the outcome of job is failed because of execution error in third store procedure(Indicated in yellow color).

So the question is the two store procedure(Indicated in red color) execution changes will reflect in database table or no????????????????

Thanks in Advance,

Your help is appriciated

Rohit




Oracle linked slow perfomance

$
0
0

Hi guys, I beg the moderator to move in another forum if this is not the suitable.

The issue: I got a SQL 2008r2 with an Oracle db linked. The connection is ok. I can retrieve data. Th eproblem is that I'm working using views and not table, so when I make some join the system slow down. For a query that in the software takes three minutes I have to struggle one hour. Ok we are talking about 20 thousands rows but I think that the issue is in the views because probably the "call" more than one time.

According to your experience is there a way to make the process faster? Have anyone experience using vies from Oracle?

Thanks guys

SQL 2008 R2 Common Criteria Scripts

Optimization

$
0
0

Hello Sirs:

I’m longing for the days of the SQL Server 6.x when the Execution Plans were very readable and the Query Hints were taken as written. When the optimizer had problems with a complicated query, the Query Hints where always an available turn around. Now in SQL Server 2012 I have again a very complicated Query with recursive views involved. The same Query responds almost instantly in certain conditions and takes up to 20 minutes in others. (I do not paste de Query because it is very large.)

For example if I change only one line of the query:

“WHERE idProject = 25 /* the id 25 represents a very large project with 20,000 entries, and a very acceptable response time */”

to

“WHERE idProject = 10 /* it’s a small project with 2,000 entries, and a very nasty response time */”

Curiously the optimizer takes the right decisions on the big projects and takes the bad decisions on the smaller ones.

I want to take the Execution Plan from the context in which the Query is very efficient and force the Optimizer to use that one in every case. I’ve taken months researching in the documentation, and I found that it’s possible, but I haven’t found how. Can you help me please?

Juan


JuanGN

Autogrow of file 'templog'

$
0
0

Hi'

Autogrow of file 'templog' in database 'tempdb' took 142094 milliseconds.  Consider using ALTER DATABASE to set a smaller FILEGROWTH for this file.

what is the Root clause analysis and how to troubleshoot ?

Thanks & Regards

Lakshmi Narayana


Thanks & Regards LAKSHMI NARAYANA REDDY.L

How to correlate tempdb internal objects with user query using Transaction_Id

$
0
0

Using sys.dm_tran_active_transactions I can see internal objects being created and destroyed. How can I get the SessionId/User call that generates those internal objects?  I tried using the transaction_id from sys.dm_tran_active_transactions  and look at sys.dm_tran_session_transactions but it never always match.

Thanks!

Paulo

Capacity planning for sqlserver?

$
0
0

How can we partition drive space for Data.Log and TempDB files?

Is there any formaule used to calculate the drive space allocations?

Thanks,

Ron.

Question about Insert and Update

$
0
0

Hi All,

   I have a table which gets its data from another table. The destination table has 2 columns and it has index on it, which doesn't allow duplicates. So my question is I want to create a program in SQL Server 2008 R2 itself which checks for duplicates and if the duplicate is not there then it inserts, if not it just updates, so is there a way to do this?

Thanks for any tips or help

Asha

 


xp_cmdshell completes with error code 1

$
0
0

Hello,

I have a problem with SQL servers and the xp_cmdshell command.  Both servers have the same setup  and same accounts with same permissions but one server will complete an xp_cmdshell command without an error code and the second server also completes the xp_cmdshell command with error code 1.  See below example.  Any help would be awesome.  Thanks!

declare @Error int
exec @Error = master..xp_cmdshell 'dir "c:\" '
select @Error

Running same command on server 2.

SQL Server 2005

$
0
0

The "Model" database in my SQL 2005 server displays a message saying it is not accessible. I feel this is the reason my backups (Symantec Backup Exec) have failed and now my BEDB for backups is now read-only. Can anyone help??

V/R

James Johnson

United States Navy

SQL Server Windows Authenication Problem After uninstall DNS role

$
0
0

I was attempting to setup a network domain by adding the roles DNS Server and Active Directory Domain Server roles to a windows 2008 server that I had previously setup. Note on the machine computer I had already installed SQL Server 2008 R2 which I later found out you should not do. So I uninstall the two roles. But now my SQL Server will not start\run when using an user account I setup for it to run under. It will now only run using the local system account which is not a problem. However the windows authentication logon to the database engine no longer works either. I can only logon to the database engine using SQL server login account SA. What do I have to do to get the SQL Server service to run under a user account again and how do I get SQL Server database engine to login using the windows authentication account to work again? I am trying to avoid a uninstall\reinstall of SQL Server 2008 R2 because I do not want to lose any of my SQL Server Analysis Server (SSAS) cubes that I had previously created.

I tried to run a repair on the SQL Server instance and received the following failure.

TITLE: Microsoft SQL Server 2008 R2 Setup
------------------------------

The following error has occurred:

No mapping between account names and security IDs was done.


Click 'Retry' to retry the failed action, or click 'Cancel' to cancel this action and continue setup.

For help, click: http://go.microsoft.com/fwlink?LinkID=20476&ProdName=Microsoft+SQL+Server&EvtSrc=setup.rll&EvtID=50000&ProdVer=10.50.1600.1&EvtType=0x0F90E2F6%25400xDC80C325

------------------------------
BUTTONS:

&Retry
Cancel

SqlBulkCopy error following failed SQL Server Upgrade - permissions in mssqlsystemresource database

$
0
0

Wondering if anyone has run into this before and might have suggestions about what to do about it:

We have a system that has SQL 2008 Standard Edition on it.  A few weeks back, the hosting provider tried to update the instance to SQL 2008 R2, had some problems, and rolled back to SQL 2008, restoring user database from backups in the process.

Now, we're seeing a strange error:  A SqlBulkCopy (.NET SqlClient) is failing with an error that reads "Unable to access the destination table 'my-table-name'".  Further digger with SQL Profiler, however, shows that the error really has nothing to do with that table directly.  Rather, SqlBulkCopy appears to be attempting to exec sp_tablecollations_100 @object=N'my-table-name', and it's getting the following error:

The EXECUTE permission was denied on the object 'sp_tablecollations_100', database 'mssqlsystemresource', schema 'sys'

My inclination to fix this error is to nuke the server from space and start over from backups, but that will take hours - hoping someone has a quicker path to resolution.

Ideas?

Update: We were able to confirm that whatever causes this error, it's in our database, not in mssqlsystemresource.  We confirmed this by creating a new database on the same server with the same schema, content, etc., and that database does not produce this error.


-cd Mark the best replies as answers!


Always On Availability Question mark?

$
0
0

Dear Friends,

In my production environment I have two database Servers know as SQL-DB1 (prod) and SQL-DB2 (Stand by server). I have made a cluster between two and SQL-Db1 is my primary database server. Now I used Always on availability feature on both servers and databases were synchronized.

Today I am encountering an issue. There is a small question mark icon coming on the SQL-DB1 which is shown by SQL-DB2 always on availability properties. Moreover it is also not showing that it is a primary database. Why this is happening. Secondly I am encountering a performance issue over SQL-DB2. It is not responding quickly when ever i log on to database through Management studio.

Please have a look to the snapshot


Azwar

Viewing all 12963 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>