MsSql Server , update query execution took too much time - sql-server-2008

I have a sql server db keeping our text document datas.
A specific table is keeping thousands of text paragraphs themself, This table suddenly started to respond so lately to update queries abnormally. Sometimes non-complicated basic update query takes 30 - 40 secs. to execute and asp.net application uses this table throws timeout exception.
Select queries last normal as before but update.
Why this happens and what should I do?
Server system is Windows 2008 R2 Standard and MsSql Server 2008 R2
Below's my table meta data.
CREATE TABLE [dbo].[MetinIcerikTablosuCari](
[ID] [int] IDENTITY(1,1) NOT NULL,
[MetinIsimID] [int] NOT NULL,
[MetinIsimID_Eski_1] [int] NULL,
[MetinIsimID_Eski_2] [int] NULL,
[MetinIsimID_Eski_3] [int] NULL,
[MetinIsimID_Eski_4] [int] NULL,
[MetinIsimID_Eski_5] [int] NULL,
[MetinIcindekilerID] [int] NOT NULL,
[SilmeTalebi] [bit] NULL,
[SiraNo] [int] NOT NULL,
[ParagrafMetin] [text] NOT NULL,
[RevizeParagraf] [text] NULL,
[RevizeVarMi] [bit] NULL,
[RevizasyonOnayi] [bit] NULL,
[RevizasyonTarihi] [datetime] NULL,
[RevizasyonSahibiID] [int] NULL,
[RevizasyonOnayTarihi] [datetime] NULL,
[RevizasyonOnaylayanID] [int] NULL,
[RevizasyonSonOnay] [bit] NULL,
[RevizeTuru] [int] NULL,
[ParagrafRevizeIslemJetonu] [nvarchar](50) NULL,
[BaglantiliOrtakRevizeSeriNo] [int] NULL,
[SonOnayTarihi] [datetime] NULL,
[SonOnaylayanID] [int] NULL,
[ParagrafMetin_Eski_1] [text] NULL,
[ParagrafMetin_Eski_2] [text] NULL,
[ParagrafMetin_Eski_3] [text] NULL,
[ParagrafMetin_Eski_4] [text] NULL,
[ParagrafMetin_Eski_5] [text] NULL,
[GirisTarihi] [nvarchar](50) NULL,
[YayinTarihi] [nvarchar](50) NULL,
[ParagrafNot] [nvarchar](max) NOT NULL,
[DipNotTag] [nvarchar](max) NOT NULL,
[MedyaURL] [nvarchar](100) NULL,
[MedyaUrlNot] [nvarchar](max) NOT NULL,
[VersiyonMetin] [int] NULL,
[EtkileyenMetinID] [int] NULL,
[tarih] [nvarchar](max) NULL,
[GuncellemeTarihi] [datetime] NULL,
[NotParagrafi] [bit] NULL,
[YeniParagraf] [bit] NULL,
[MedyaParagrafi] [bit] NULL,
[EslestirmeSilmeOnayID] [int] NULL,
[YargiOnBilgiSayfasi] [bit] NULL,
[BolumParagrafi] [bit] NULL,
[UstParagrafID] [int] NULL,
CONSTRAINT [PK_MetinIcerikTablosuCari] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
ALTER TABLE [dbo].[MetinIcerikTablosuCari] ADD CONSTRAINT [DF_MetinIcerikTablosuCari_MetinIsimID] DEFAULT ((0)) FOR [MetinIsimID]
GO
ALTER TABLE [dbo].[MetinIcerikTablosuCari] ADD CONSTRAINT [DF_MetinIcerikTablosuCari_MetinIcindekilerID] DEFAULT ((0)) FOR [MetinIcindekilerID]
GO
ALTER TABLE [dbo].[MetinIcerikTablosuCari] ADD CONSTRAINT [DF_MetinIcerikTablosuCari_SiraNo] DEFAULT ((0)) FOR [SiraNo]
GO
ALTER TABLE [dbo].[MetinIcerikTablosuCari] ADD CONSTRAINT [DF_MetinIcerikTablosuCari_ParagrafMetin] DEFAULT ('') FOR [ParagrafMetin]
GO
ALTER TABLE [dbo].[MetinIcerikTablosuCari] ADD CONSTRAINT [DF_MetinIcerikTablosuCari_RevizeTuru] DEFAULT ((1)) FOR [RevizeTuru]
GO
ALTER TABLE [dbo].[MetinIcerikTablosuCari] ADD CONSTRAINT [DF_MetinIcerikTablosuCari_ParagrafNot] DEFAULT ('') FOR [ParagrafNot]
GO
ALTER TABLE [dbo].[MetinIcerikTablosuCari] ADD CONSTRAINT [DF_MetinIcerikTablosuCari_DipNotTag] DEFAULT ('') FOR [DipNotTag]
GO
ALTER TABLE [dbo].[MetinIcerikTablosuCari] ADD CONSTRAINT [DF_MetinIcerikTablosuCari_MedyaUrlNot] DEFAULT ('') FOR [MedyaUrlNot]
GO
ALTER TABLE [dbo].[MetinIcerikTablosuCari] ADD CONSTRAINT [DF_MetinIcerikTablosuCari_NotParagrafi] DEFAULT ((0)) FOR [NotParagrafi]
GO
ALTER TABLE [dbo].[MetinIcerikTablosuCari] ADD CONSTRAINT [DF_MetinIcerikTablosuCari_YeniParagraf] DEFAULT ((0)) FOR [YeniParagraf]
GO
ALTER TABLE [dbo].[MetinIcerikTablosuCari] ADD CONSTRAINT [DF_MetinIcerikTablosuCari_MedyaParagrafi] DEFAULT ((0)) FOR [MedyaParagrafi]
GO
ALTER TABLE [dbo].[MetinIcerikTablosuCari] ADD CONSTRAINT [DF_MetinIcerikTablosuCari_EslestirmeSilmeOnayID] DEFAULT ((0)) FOR [EslestirmeSilmeOnayID]
GO
ALTER TABLE [dbo].[MetinIcerikTablosuCari] ADD CONSTRAINT [DF_MetinIcerikTablosuCari_YargiOnBilgiSayfasi] DEFAULT ((0)) FOR [YargiOnBilgiSayfasi]
GO
ALTER TABLE [dbo].[MetinIcerikTablosuCari] ADD CONSTRAINT [DF_MetinIcerikTablosuCari_BolumParagrafi] DEFAULT ((0)) FOR [BolumParagrafi]
GO
I checked out and executed the update stats sp, but it seems the problem keeps going.
A simple update query like this: update MetinIcerikTablosuCari set ParagrafMetin = '<p>SPK Bültenleri - 2002/34: #media#93640#media#</p>' where ID = 35606 takes 20 - 30 secs or more.
I checked the CPU usage while the query executing, it suddenly picks to appr. 75 - 80%.
I could not determine if it's about lack of server memory or sql uses memory abnormally.
Below is my server hardware specifications:
Windows 2008 R2 Standard - Service Pack1
Processor: Intel Core i5-2400 CPU # 3.1 Ghz
RAM: 8GB
System Type: 64-bit
In addition, could this be kind of lack of updates for Windows Server or MsSql Server 2008 r2

As you haven't provided the execution plan and other necessary details, my assumption is that you might have indexes which are causing slow updates. Indexes helps running SELECT fast but slow down insert and update statements. List out all the indexes (Clustered & Non-Clustered) and then remove unnecessary indexes from your table.
Also, how often do you update statistics? If that is not recently done then run following SP
EXEC Sp_Updatestats;
If above two ways doesn't solve your problem then I recommend you to post table metadata and execution plan.

Related

SQL statement with square brackets AUTO_INCREMENT error

My new VPN accepts only sql statements with square brackets hence I edited the traditional sql query to:
CREATE TABLE admin (
[id] int(11) NOT NULL AUTO_INCREMENT,
[name] varchar(128) NOT NULL,
[email] varchar(64) NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2;
But it shows this error:
Msg 102, Level 15, State 1, Line 1 Incorrect syntax near
'AUTO_INCREMENT'
Basically the server is windows azure and I am using Microsoft SQL server management studio to execute sql queries.
CREATE TABLE [dbo].[admin](
[id] [int](11) IDENTITY(1,1) NOT NULL,
[name] [varchar](128) NULL,
[email] [varchar](64) NULL,
CONSTRAINT [PK_admin] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
In sql server should be created auto increment to use IDENTITY not AUTO_INCREMENT. Like this
CREATE TABLE admin (
[id] int(11) IDENTITY(1,1) NOT NULL ,
[name] varchar(128) NOT NULL,
[email] varchar(64) NOT NULL,
PRIMARY KEY (id)
)
More detail to refer this link http://www.w3schools.com/sql/sql_create_table.asp
CREATE TABLE [dbo].[admin](
[ID] [int]IDENTITY(1,2) NOT FOR REPLICATION NOT NULL,
[name] [char](128) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[email] [varchar](64) NOT NULL,
PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

MySql Performance issue vs SQL-Server

I've created a table with 50 million rows on MSSQLServer 2008R2 and MYSQL WorkBench 6.1.
I'm not sure why this query take 16Sec on MySql but 0 Sec on SQL-Server?
SELECT avg(speed) FROM tm where RoadId%5=0 and time%3=0;
-Performance difference exists with different where clauses.
-SQL-Server and MySQL both installed in one machine with 128 GB of Ram and 16 core CPU.
ps: This is script to create table on SQL-Server
CREATE TABLE [dbo].[TM](
[RoadId] [int] NOT NULL,
[Date] [smallint] NOT NULL,
[Time] [tinyint] NOT NULL,
[VType] [tinyint] NOT NULL,
[Speed] [tinyint] NOT NULL,
CONSTRAINT [PK_TM_1] PRIMARY KEY CLUSTERED
(
[RoadId] ASC,
[Date] ASC,
[Time] ASC,
[VType] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
and MySQL:
CREATE TABLE `tm` (
`RoadId` int(11) NOT NULL,
`Date` smallint(6) NOT NULL,
`Time` tinyint(3) unsigned NOT NULL,
`VType` tinyint(3) unsigned NOT NULL,
`Speed` tinyint(3) unsigned NOT NULL,
PRIMARY KEY (`RoadId`,`Date`,`Time`,`VType`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
SQL Server automatically implements parallelism for this type of query, whereas mysql does not. This basically means that SQL will divide up the table scan and analyze rows with multiple threads. I believe mysql requires the data to be partitioned in order to achieve this same functionality.

Import sql syntax, Windows SQL Server and Apache Mysql

I have below sql export from Microsoft SQL Sever and I tried to import into Mysql running by Apache in osx. I got an Sql syntax error from line 1. I am new and I actually have never seen the sql using [ ] as quote fot string.
May I ask is the sql different from Sql Server in Windows and the
Mysql in Apache?
If I want to import below database into mysql, what should I check
and look at?
Thank you very much for your adverses!!
Best regards,
USE [boatexpress]
GO
/****** Object: Schema [boatexpress] Script Date: 07/22/2013 14:15:07 ******/
CREATE SCHEMA [boatexpress] AUTHORIZATION [boatexpress]
GO
/****** Object: Table [dbo].[waybill111] Script Date: 07/22/2013 14:15:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[waybill111](
[id] [int] IDENTITY(1,1) NOT NULL,
[slAAECode] [nvarchar](100) NULL,
[slProductName] [ntext] NULL,
[slRecName] [nvarchar](50) NULL,
[slRecMobi] [nvarchar](50) NULL,
[slRecAddress] [nvarchar](255) NULL,
[slZipCode] [nvarchar](50) NULL,
[slweight] [float] NULL,
[ktype] [nvarchar](50) NULL,
[worth] [nvarchar](150) NULL,
[adminid] [int] NULL,
[addtime] [date] NULL,
[insurance] [nvarchar](50) NULL,
CONSTRAINT [PK_waybill] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
The syntax from SQL to MySQL is different. If you want to create above table use this syntax.
Create the database
CREATE SCHEMA `boatexpress` ;
Create the table
CREATE TABLE boatexpress.waybill111 (
`id` int PRIMARY KEY AUTO_INCREMENT NOT NULL,
`slAAECode` nvarchar(100) NULL,
`slProductName` text NULL,
`slRecName` nvarchar(50) NULL,
`slRecMobi` nvarchar(50) NULL,
`slRecAddress` nvarchar (255) NULL,
`slZipCode` nvarchar(50) NULL,
`slweight` float NULL,
`ktype` nvarchar(50) NULL,
`worth` nvarchar(150) NULL,
`adminid` int NULL,
`addtime` date NULL,
`insurance` nvarchar(50) NULL);
Datatypes like ntext doesnt exists in MySQL. I just renamed it to TEXT. Also [] are not used to wrap columns but ` is. For datatypes you dont need to enclose them at all.
Is this what you are looking for?
Also, your SQL code is actually trying to use boatexpress before creating it.

SQL Server 2008 Foreign Key Constraint Error

I am creating a database with series of tables ddls, and in all are 13 tables. I am getting a foreign key constraint error when I run the ddl for TBNSOR_VICTIM table. The ddl was able to create the first fk constraint but I get an error creating the second fk constraint. Can somebody help me out or point me to what am missing in the scripts? This is the error am getting after running the ddl scripts
Msg 1776, Level 16, State 0, Line 2
There are no primary or candidate keys in the referenced table 'dbo.TBNSOR_OFFENSE' that match the referencing column list in the foreign key 'RD09RD03'
CREATE TABLE [dbo].[TBNSOR_OFFENSE](
[RD03_RC27SEQ_NBR] [int] NOT NULL,
[FK_RD01_RC17SID] [int] NOT NULL,
[RD03_RC27OFFENSE_DESC] [varchar] (100) NULL,
[RD03_STATUTE] [char](6) NULL,
[RD03_RC27PREDATOR_IND] [char] (1) NULL,
[RD03_RC27CONVICTION_DT] [date] NULL,
[RD03_RC27CONVICT_CITY] [varchar] (20) NULL,
[RD03_RC27CONVICT_STATE] [char] (2) NULL,
[RD03_RC27CONVICT_COUNTY] [varchar] (20) NULL,
[RD03_RC27CITY] [varchar] (20) NULL,
[RD03_RC27COUNTY] [varchar] (20) NULL,
[RD03_RC27OFFENSE_STATE] [char] (2) NULL,
[RD03_RC27OFFENSE_DATE] [date] NULL,
[RD03_RC27CONFIN_REL_DT] [date] NULL,
[RD03_RC27PP_RELEASE_DT] [date] NULL,
CONSTRAINT [CJ38ID03] PRIMARY KEY CLUSTERED
(
[RD03_RC27SEQ_NBR] ASC,
[FK_RD01_RC17SID] 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
SET ANSI_PADDING OFF
GO
ALTER TABLE [dbo].[TBNSOR_OFFENSE] WITH CHECK ADD CONSTRAINT [RD03RD01] FOREIGN KEY([FK_RD01_RC17SID])
REFERENCES [dbo].[TBNSOR_PHYSCSC] ([RD01_RC17SID])ON DELETE CASCADE
GO
ALTER TABLE [dbo].[TBNSOR_OFFENSE] CHECK CONSTRAINT [RD03RD01]
GO
CREATE TABLE [dbo].[TBNSOR_VICTIM](
[RD09_RC28SEQ_NUM] [int] NOT NULL,
[FK_RD01_RC17SID] [int] NOT NULL,
[FK_RD03_RC27SEQ_NBR] [int] NOT NULL,
[RD09_RC28SEX] [char] (1) NULL,
[RD09_RC28RACE] [char] (1) NULL,
[RD09_RC28AGE] [char](2) NULL,
[RD09_RC28HIGH_AGE] [char] (2) NULL,
[RD09_RC28LOW_AGE] [char] (2) NULL,
CONSTRAINT [CJ38ID09] PRIMARY KEY CLUSTERED
(
[RD09_RC28SEQ_NUM] ASC,
[FK_RD01_RC17SID] ASC,
[FK_RD03_RC27SEQ_NBR] 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
SET ANSI_PADDING OFF
GO
ALTER TABLE [dbo].[TBNSOR_VICTIM] WITH CHECK ADD CONSTRAINT [RD09RD01] FOREIGN KEY([FK_RD01_RC17SID])
REFERENCES [dbo].[TBNSOR_PHYSCSC] ([RD01_RC17SID])ON DELETE CASCADE
GO
ALTER TABLE [dbo].[TBNSOR_VICTIM] CHECK CONSTRAINT [RD09RD01]
GO
ALTER TABLE [dbo].[TBNSOR_VICTIM] WITH CHECK ADD CONSTRAINT [RD09RD03] FOREIGN KEY([FK_RD03_RC27SEQ_NBR])
REFERENCES [dbo].[TBNSOR_OFFENSE]([RD03_RC27SEQ_NBR])ON DELETE CASCADE
GO
ALTER TABLE [dbo].[TBNSOR_VICTIM] CHECK CONSTRAINT [RD09RD03]
GO
You have primary key set up on two columns ([RD03_RC27SEQ_NBR] and [FK_RD01_RC17SID]) in [CJ38TBNSOR_OFFENSE] table, but your referencing just one of them.
It should be:
REFERENCES [cj38].[CJ38TBNSOR_OFFENSE]([RD03_RC27SEQ_NBR],[FK_RD01_RC17SID])

Suggestions on storing view meta in SQL Server 2008

I want to store the view meta info like on which tables & columns & queries its created etc,
into another mapping table,so that I can reproduce them later point of time.
Right now I have a structure like this -
CREATE TABLE [dbo].[MAPPING_VIEW]
(
[ID] [int] NOT NULL,
[OLD_VIEW] [varchar](40) NULL,
[NEW_VIEW] [varchar](40) NULL,
CONSTRAINT [PK_MAPPING_VIEW] PRIMARY KEY CLUSTERED
([ID] ASC)
)
CREATE TABLE [dbo].[MAPPING_VIEW_TBL]
(
[ID] [int] NULL,
[PARENT_ID] [int] NULL,
[OLD_TBL] [varchar](40) NULL,
[NEW_TBL] [varchar](40) NULL
)
ALTER TABLE [dbo].[MAPPING_VIEW_TBL] WITH NOCHECK
ADD CONSTRAINT [FK_MAPPING_VIEW_TBL_ID]
FOREIGN KEY([PARENT_ID]) REFERENCES [dbo].[MAPPING_VIEW] ([ID])
CREATE TABLE [dbo].[MAPPING_VIEW_TBL_COL]
(
[ID] [int] NULL,
[PARENT_ID] [int] NULL,
[VIEW_ID] [int] NULL,
[OLD_COL] [varchar](40) NULL,
[NEW_COL] [varchar](40) NULL,
[OLD_ALIAS] [varchar](40) NULL,
[NEW_ALIAS] [varchar](40) NULL
)
ALTER TABLE [dbo].[MAPPING_VIEW_TBL_COL] WITH NOCHECK
ADD CONSTRAINT [FK_MAPPING_VIEW_TBL_COL_PARENT_ID]
FOREIGN KEY([PARENT_ID]) REFERENCES [dbo].[MAPPING_TBL] ([ID])
ALTER TABLE [dbo].[MAPPING_VIEW_TBL_COL] WITH NOCHECK
ADD CONSTRAINT [FK_MAPPING_VIEW_TBL_COL_VIEW_ID]
FOREIGN KEY([VIEW_ID]) REFERENCES [dbo].[MAPPING_VIEW] ([ID])
I know, which is not enough. Any suggestions would be appreciated