Showing posts with label primary. Show all posts
Showing posts with label primary. Show all posts

Thursday, March 29, 2012

Error loading tables of different file groups.

Hi All,

I am facing a peculier problem. Problem definition goes like this,

I have one staging DB in which all the tables resides in Primary file and one production DB in which tables resides in 2 secondary files.

Now when iam trying to load the data from the table A in staging which is on primary file to the table A1 in production DB which in secondary file, all the data are going to error log instead of table A1.

Can you please tell me, where am i going wrong.

Regards,

Chetan

No. Not without the error message. Can you provide it?

-Jamie

|||

HI Jamie,

Sorry for that, error code and error message is as follows.

Error code:-1071607685

Error Message: No status is available.

Regards,

Chetan

sql

Monday, March 26, 2012

Error inserting record in IDENTITY column

Hi,
I have a counter field with data type IDENTITY in a table which should have
primary key constraint to that ID field.
When it tried to insert a new record, it has error "cannot insert duplicate
key in the counter field" because of the constraint.
Supposed that whenever adding a new record, it should add the increment to
the last ID. How can I fix it to allow inserting new records ?
Regards,
JTWhat version of SQL Server? Seems like the internal counter for the identity value is messed up,
something I haven't seen since the 6.5 days. Read up on DBCC CHECKIDENT, that should be able to fix
it for you.
Of course, I assume you don't use SET IDENTITY_INSERT ON and specify a value for the identity
column.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Johnny" <Johnny@.discussions.microsoft.com> wrote in message
news:8D318201-8122-49E6-A710-558B161A4069@.microsoft.com...
> Hi,
> I have a counter field with data type IDENTITY in a table which should have
> primary key constraint to that ID field.
> When it tried to insert a new record, it has error "cannot insert duplicate
> key in the counter field" because of the constraint.
> Supposed that whenever adding a new record, it should add the increment to
> the last ID. How can I fix it to allow inserting new records ?
> Regards,
> JT|||Johnny
How do you insert the values?
create table #tmp (id int not null identity(1,1) primary key, c char(1) not
null)
go
insert into #tmp(c) values ('a')
insert into #tmp(c) values ('b')
insert into #tmp(c) values (c')
go
select * from #tmp
"Johnny" <Johnny@.discussions.microsoft.com> wrote in message
news:8D318201-8122-49E6-A710-558B161A4069@.microsoft.com...
> Hi,
> I have a counter field with data type IDENTITY in a table which should
> have
> primary key constraint to that ID field.
> When it tried to insert a new record, it has error "cannot insert
> duplicate
> key in the counter field" because of the constraint.
> Supposed that whenever adding a new record, it should add the increment to
> the last ID. How can I fix it to allow inserting new records ?
> Regards,
> JT

Sunday, March 11, 2012

Error in Replication how to continue

I have transactional Replication from A to B.

My distribution agent failed becos of a primary key violation error in a table.[i have not included the skip error option].

Then the replication stopped.
The transactions on other tables are also not replicated to B.

IF an error is encountered in one of the tables will the replication stop entirely??.Is there no way for the replication to continue for the rest of the tables..
Pls clarifyI don't think you can skip this error. To use Replication you have to have a primary key in the table you want to replicate.|||The transactions are processed in a serialized fashion, meaning that if one failed nothing else goes through.

Error in my 8 table SQL Script

/*Script Start*/

create database HorizonAirways

create table Sector
(
SectorID Char(5) constraint SectorID primary key clustered not null,
Description VarChar(50) not null,
WeekDay1 char(3) not null,
WeekDay2 char(3) not null,
FirstClassFare Money not null,
BusinessClassFare Money not null,
EconomyClassFare Money not null
)

select * from Sector

create table Aircraft
(
AircraftTypeID char(4) constraint AircraftTypeID primary key clustered not null,
Description char(30) not null,
FirstClassSeats int not null,
BusinessClassSeats int not null,
EconomyClassSeats int not null
)
select * from Aircraft

create table flights
(
FlightNo char(5) constraint FlightNo primary key clustered not null,
DepTime char(5) not null,
ArrTime char(5) not null,
AircraftTypeID char(4) references Aircraft(AircraftTypeID) not null,
SectorID Char(5) references Sector(SectorID) not null
)

select * from Flights

create table ScheduledFlights
(
FlightNo char(5) references flights(FlightNo) not null,
FlightDate datetime not null,
FirstClassSeatsAvailable int not null,
BusinessClassSeatsAvailable int not null,
EconomyClassSeatsAvailable int not null
)

select * from ScheduledFlights

create table passenger
(
PnrNo char(8) constraint PNR primary key clustered not null,
FlightNo char(5) references flights(FlightNo) not null,

TravelDate datetime constraint PassengerFlights Foreign key (FlightNo, DeptTime) references flights (FlightNo,DepTime) not null,

FName char(20) not null,
LName char(20) not null,
Age int not null,
Gender char(1) not null,
Class char(15) not null,
SeatPref char(6) not null,
MealPref char(15) not null,
SSR varchar(100) not null,
Status char(15)
)

create table DailyCollection
(
PnrNo char(8) references Passenger(PnrNo) not null,
TransDate Datetime not null,
TranType Char(1) not null,
Amount Float not null
)

create table users
(
UserName char(15) constraint Username primary key clustered not null,
Password char(15) not null,
UserRole Char(15) not null
)

!!OUTPUT!!

--
Msg 8140, Level 16, State 0, Line 48
More than one key specified in column level FOREIGN KEY constraint, table 'passenger'.
Msg 1769, Level 16, State 1, Line 48
Foreign key 'PassengerFlights' references invalid column 'DeptTime' in referencing table 'passenger'.
Msg 1750, Level 16, State 0, Line 48
Could not create constraint. See previous errors.
--

--
In the project given by our teacher it says about Passenger Table
Pnr(PK)- Char (8) no null values

FlightNo- Char(5) no null values

TravelDate- DateTime no null values
info-Date of travel. The flight number and the date of travel together gorm a foreign key that references the flight number and the flight date in theFlight Table.
--
rest is fine.....

CAN ANYONE PLEASE RECTIFY THESE ERRORS ?
There are some typos in your script as well as problem with contraints. My preferable way to define constraints is to use separate statements instead of inline within the table creation script. I addition you can only reference primary keys (one or more column as a combound key) with a foreign key constraint. So you will either have to extend the primary key in the flights table to the DeptTime ot narrow the foreign key on the passenger table to flightNo only. As of my knowledge about flight it has to be the first solution, right ? :-)

create table passenger

(

PnrNo char(8) constraint PNR primary key clustered not null,

FlightNo char(5) not null,

FName char(20) not null,

LName char(20) not null,

Age int not null,

Gender char(1) not null,

Class char(15) not null,

SeatPref char(6) not null,

MealPref char(15) not null,

SSR varchar(100) not null,

Status char(15),

TravelDate datetime

)

ALTER TABLE Passenger

ADD CONSTRAINT FK_Passenger_Flights FOREIGN KEY (FlightNo, TravelDate)

references flights(FlightNo, DepTime)

HTH, Jens K. Suessmeyer.

http://www.sqlserver2005.de

|||Thank you very much.

In future i will use your way. I will define constraints separately. Cheers !!
|||Great reply and its works..

Error in my 8 table SQL Script

/*Script Start*/

create database HorizonAirways

create table Sector
(
SectorID Char(5) constraint SectorID primary key clustered not null,
Description VarChar(50) not null,
WeekDay1 char(3) not null,
WeekDay2 char(3) not null,
FirstClassFare Money not null,
BusinessClassFare Money not null,
EconomyClassFare Money not null
)

select * from Sector

create table Aircraft
(
AircraftTypeID char(4) constraint AircraftTypeID primary key clustered not null,
Description char(30) not null,
FirstClassSeats int not null,
BusinessClassSeats int not null,
EconomyClassSeats int not null
)
select * from Aircraft

create table flights
(
FlightNo char(5) constraint FlightNo primary key clustered not null,
DepTime char(5) not null,
ArrTime char(5) not null,
AircraftTypeID char(4) references Aircraft(AircraftTypeID) not null,
SectorID Char(5) references Sector(SectorID) not null
)

select * from Flights

create table ScheduledFlights
(
FlightNo char(5) references flights(FlightNo) not null,
FlightDate datetime not null,
FirstClassSeatsAvailable int not null,
BusinessClassSeatsAvailable int not null,
EconomyClassSeatsAvailable int not null
)

select * from ScheduledFlights

create table passenger
(
PnrNo char(8) constraint PNR primary key clustered not null,
FlightNo char(5) references flights(FlightNo) not null,

TravelDate datetime constraint PassengerFlights Foreign key (FlightNo, DeptTime) references flights (FlightNo,DepTime) not null,

FName char(20) not null,
LName char(20) not null,
Age int not null,
Gender char(1) not null,
Class char(15) not null,
SeatPref char(6) not null,
MealPref char(15) not null,
SSR varchar(100) not null,
Status char(15)
)

create table DailyCollection
(
PnrNo char(8) references Passenger(PnrNo) not null,
TransDate Datetime not null,
TranType Char(1) not null,
Amount Float not null
)

create table users
(
UserName char(15) constraint Username primary key clustered not null,
Password char(15) not null,
UserRole Char(15) not null
)

!!OUTPUT!!

--
Msg 8140, Level 16, State 0, Line 48
More than one key specified in column level FOREIGN KEY constraint, table 'passenger'.
Msg 1769, Level 16, State 1, Line 48
Foreign key 'PassengerFlights' references invalid column 'DeptTime' in referencing table 'passenger'.
Msg 1750, Level 16, State 0, Line 48
Could not create constraint. See previous errors.
--

--
In the project given by our teacher it says about Passenger Table
Pnr(PK)- Char (8) no null values

FlightNo- Char(5) no null values

TravelDate- DateTime no null values
info-Date of travel. The flight number and the date of travel together gorm a foreign key that references the flight number and the flight date in the Flight Table.
--
rest is fine.....

CAN ANYONE PLEASE RECTIFY THESE ERRORS ?There are some typos in your script as well as problem with contraints. My preferable way to define constraints is to use separate statements instead of inline within the table creation script. I addition you can only reference primary keys (one or more column as a combound key) with a foreign key constraint. So you will either have to extend the primary key in the flights table to the DeptTime ot narrow the foreign key on the passenger table to flightNo only. As of my knowledge about flight it has to be the first solution, right ? :-)

create table passenger

(

PnrNo char(8) constraint PNR primary key clustered not null,

FlightNo char(5) not null,

FName char(20) not null,

LName char(20) not null,

Age int not null,

Gender char(1) not null,

Class char(15) not null,

SeatPref char(6) not null,

MealPref char(15) not null,

SSR varchar(100) not null,

Status char(15),

TravelDate datetime

)

ALTER TABLE Passenger

ADD CONSTRAINT FK_Passenger_Flights FOREIGN KEY (FlightNo, TravelDate)

references flights(FlightNo, DepTime)

HTH, Jens K. Suessmeyer.

http://www.sqlserver2005.de

|||Thank you very much.

In future i will use your way. I will define constraints separately. Cheers !!|||Great reply and its works..

Wednesday, March 7, 2012

Error in Identity Column

For some reason my primary key, identity column skipped a couple of numbers. It went from row 734 to 736, 737, 739

Any ideas why this would happen?

thanks

hi

735 & 738 must've been created but deleted somehow.

|||

No, it was not deleted

|||

Rick0194:

No, it was not deleted

Yes they were, that's the only way it could have been skipped. Now, it may be that they get inserted as part of a transaction and something goes wrong and rolls it back -- the identity colum's value will appear to skip the next time a good insert occurs (I just confirmed that on sql 2000)

Wednesday, February 15, 2012

Error Handling in SQL?

Hi there,
A insert query fails because of the erroneous data (primary key violation,
data type mismatch, etc). This insert statement is in the middle of a stored
procedure, which is part of a large system. We don't have the error handling
code in the system. Whenver error happens, it simply exits.
The big problem is that for such case, one bad record in the insert query
can take down the entire system.
It will be ideal if this query can automatically re-run when it failed in
the first run and filter out the "problem" records and succeed in the second
attempt without taking down the entire system.
Any idea, sample code or suggestion are highly appreciated.
LX
http://www.sommarskog.se/error-handling-I.html
http://www.sommarskog.se/error-handling-II.html
will get you started.
Jacco Schalkwijk
SQL Server MVP
"FLX" <nospam@.hotmail.com> wrote in message
news:%23qlKbtXeEHA.724@.TK2MSFTNGP10.phx.gbl...
> Hi there,
> A insert query fails because of the erroneous data (primary key violation,
> data type mismatch, etc). This insert statement is in the middle of a
> stored
> procedure, which is part of a large system. We don't have the error
> handling
> code in the system. Whenver error happens, it simply exits.
> The big problem is that for such case, one bad record in the insert query
> can take down the entire system.
> It will be ideal if this query can automatically re-run when it failed in
> the first run and filter out the "problem" records and succeed in the
> second
> attempt without taking down the entire system.
> Any idea, sample code or suggestion are highly appreciated.
> LX
>

Error Handling in SQL?

Hi there,
A insert query fails because of the erroneous data (primary key violation,
data type mismatch, etc). This insert statement is in the middle of a stored
procedure, which is part of a large system. We don't have the error handling
code in the system. Whenver error happens, it simply exits.
The big problem is that for such case, one bad record in the insert query
can take down the entire system.
It will be ideal if this query can automatically re-run when it failed in
the first run and filter out the "problem" records and succeed in the second
attempt without taking down the entire system.
Any idea, sample code or suggestion are highly appreciated.
LXhttp://www.sommarskog.se/error-handling-I.html
http://www.sommarskog.se/error-handling-II.html
will get you started.
Jacco Schalkwijk
SQL Server MVP
"FLX" <nospam@.hotmail.com> wrote in message
news:%23qlKbtXeEHA.724@.TK2MSFTNGP10.phx.gbl...
> Hi there,
> A insert query fails because of the erroneous data (primary key violation,
> data type mismatch, etc). This insert statement is in the middle of a
> stored
> procedure, which is part of a large system. We don't have the error
> handling
> code in the system. Whenver error happens, it simply exits.
> The big problem is that for such case, one bad record in the insert query
> can take down the entire system.
> It will be ideal if this query can automatically re-run when it failed in
> the first run and filter out the "problem" records and succeed in the
> second
> attempt without taking down the entire system.
> Any idea, sample code or suggestion are highly appreciated.
> LX
>|||data type mis-match will abort processing, primary key errors won't. Jacco's
already pointed you out to the best articles available on tsql error
handling but I'd add that you really need to handle error conditions in your
client application if you want re-try logic. It's the only place where
that's even possible if TSQL aborts processing..
HTH
Regards,
Greg Linwood
SQL Server MVP
"FLX" <nospam@.hotmail.com> wrote in message
news:%23qlKbtXeEHA.724@.TK2MSFTNGP10.phx.gbl...
> Hi there,
> A insert query fails because of the erroneous data (primary key violation,
> data type mismatch, etc). This insert statement is in the middle of a
stored
> procedure, which is part of a large system. We don't have the error
handling
> code in the system. Whenver error happens, it simply exits.
> The big problem is that for such case, one bad record in the insert query
> can take down the entire system.
> It will be ideal if this query can automatically re-run when it failed in
> the first run and filter out the "problem" records and succeed in the
second
> attempt without taking down the entire system.
> Any idea, sample code or suggestion are highly appreciated.
> LX
>

Error Handling in SQL?

Hi there,
A insert query fails because of the erroneous data (primary key violation,
data type mismatch, etc). This insert statement is in the middle of a stored
procedure, which is part of a large system. We don't have the error handling
code in the system. Whenver error happens, it simply exits.
The big problem is that for such case, one bad record in the insert query
can take down the entire system.
It will be ideal if this query can automatically re-run when it failed in
the first run and filter out the "problem" records and succeed in the second
attempt without taking down the entire system.
Any idea, sample code or suggestion are highly appreciated.
LXhttp://www.sommarskog.se/error-handling-I.html
http://www.sommarskog.se/error-handling-II.html
will get you started.
--
Jacco Schalkwijk
SQL Server MVP
"FLX" <nospam@.hotmail.com> wrote in message
news:%23qlKbtXeEHA.724@.TK2MSFTNGP10.phx.gbl...
> Hi there,
> A insert query fails because of the erroneous data (primary key violation,
> data type mismatch, etc). This insert statement is in the middle of a
> stored
> procedure, which is part of a large system. We don't have the error
> handling
> code in the system. Whenver error happens, it simply exits.
> The big problem is that for such case, one bad record in the insert query
> can take down the entire system.
> It will be ideal if this query can automatically re-run when it failed in
> the first run and filter out the "problem" records and succeed in the
> second
> attempt without taking down the entire system.
> Any idea, sample code or suggestion are highly appreciated.
> LX
>|||data type mis-match will abort processing, primary key errors won't. Jacco's
already pointed you out to the best articles available on tsql error
handling but I'd add that you really need to handle error conditions in your
client application if you want re-try logic. It's the only place where
that's even possible if TSQL aborts processing..
HTH
Regards,
Greg Linwood
SQL Server MVP
"FLX" <nospam@.hotmail.com> wrote in message
news:%23qlKbtXeEHA.724@.TK2MSFTNGP10.phx.gbl...
> Hi there,
> A insert query fails because of the erroneous data (primary key violation,
> data type mismatch, etc). This insert statement is in the middle of a
stored
> procedure, which is part of a large system. We don't have the error
handling
> code in the system. Whenver error happens, it simply exits.
> The big problem is that for such case, one bad record in the insert query
> can take down the entire system.
> It will be ideal if this query can automatically re-run when it failed in
> the first run and filter out the "problem" records and succeed in the
second
> attempt without taking down the entire system.
> Any idea, sample code or suggestion are highly appreciated.
> LX
>