dbTalk Databases Forums  

INSERT Statment has another prolbem.

comp.databases comp.databases


Discuss INSERT Statment has another prolbem. in the comp.databases forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Chase Preuninger
 
Posts: n/a

Default INSERT Statment has another prolbem. - 05-17-2008 , 06:26 AM






I got it to work but now I can figure out why I can't insert another
row referring to chasepreuninger. It works the first time then it
just fails.

CREATE TABLE Accounts (Account_Name VARCHAR(100) PRIMARY KEY,
First_Name VARCHAR(50) NOT NULL, Last_Name VARCHAR(100) NOT NULL,
Email_Address VARCHAR(300) NOT NULL);
CREATE TABLE Notes (Note_ID INTEGER PRIMARY KEY, Note_Owner
VARCHAR(100) REFERENCES Accounts(Account_Name), Note_TITLE
VARCHAR(50) NOT NULL, Note_Description VARCHAR(500) NOT NULL,
Note_Keywords VARCHAR(300) NOT NULL, Note_Location VARCHAR(100) NOT
NULL UNIQUE);
DROP TABLE Notes;

INSERT INTO Accounts VALUES('chasepreuninger', 'Chase', 'Preuninger',
'chasepreuninger (AT) gmail (DOT) com');
SELECT * FROM Accounts;

INSERT INTO Notes VALUES(3, 'chasepreuninger', 'Bio Lab 7', 'Here is
the lab we did today!', 'bio, biology', '5645656.doc');
SELECT * FROM Notes;

Error code -1, SQL state 23505: The statement was aborted because it
would have caused a duplicate key value in a unique or primary key
constraint or unique index identified by 'SQL080516093435302' defined
on 'NOTES'.
Line 8, column 1

Reply With Quote
  #2  
Old   
Andrea Montanari
 
Posts: n/a

Default Re: INSERT Statment has another prolbem. - 05-17-2008 , 07:48 AM






hi,
Chase Preuninger wrote:
Quote:
I got it to work but now I can figure out why I can't insert another
row referring to chasepreuninger. It works the first time then it
just fails.

CREATE TABLE Accounts (Account_Name VARCHAR(100) PRIMARY KEY, ....
this is the italian localized NG for SQL Server, and questions should be
posted in italian..

your table is defined with a primary key on the Account_Name column..
primary key implies a unique value and this is the reason you can not insert
a duplicate for that column's value..
try defining another primary key instead the actual one.. you could perhaps
use an artificial key, perhaps based on a numeric column with an
autogenerated value like the Identity property provides..
read further about artificial keys in
http://www.intelligententerprise.com...leID=201806814
regards
--
Andrea Montanari (Microsoft MVP - SQL Server)
http://www.asql.biz http://www.hotelsole.com
DbaMgr2k ver 0.21.1 - DbaMgr ver 0.65.1 and further SQL Tools
--------- remove DMO to reply




Reply With Quote
  #3  
Old   
Andrea Montanari
 
Posts: n/a

Default Re: INSERT Statment has another prolbem. - 05-17-2008 , 07:48 AM



hi,
Chase Preuninger wrote:
Quote:
I got it to work but now I can figure out why I can't insert another
row referring to chasepreuninger. It works the first time then it
just fails.

CREATE TABLE Accounts (Account_Name VARCHAR(100) PRIMARY KEY, ....
this is the italian localized NG for SQL Server, and questions should be
posted in italian..

your table is defined with a primary key on the Account_Name column..
primary key implies a unique value and this is the reason you can not insert
a duplicate for that column's value..
try defining another primary key instead the actual one.. you could perhaps
use an artificial key, perhaps based on a numeric column with an
autogenerated value like the Identity property provides..
read further about artificial keys in
http://www.intelligententerprise.com...leID=201806814
regards
--
Andrea Montanari (Microsoft MVP - SQL Server)
http://www.asql.biz http://www.hotelsole.com
DbaMgr2k ver 0.21.1 - DbaMgr ver 0.65.1 and further SQL Tools
--------- remove DMO to reply




Reply With Quote
  #4  
Old   
Andrea Montanari
 
Posts: n/a

Default Re: INSERT Statment has another prolbem. - 05-17-2008 , 07:48 AM



hi,
Chase Preuninger wrote:
Quote:
I got it to work but now I can figure out why I can't insert another
row referring to chasepreuninger. It works the first time then it
just fails.

CREATE TABLE Accounts (Account_Name VARCHAR(100) PRIMARY KEY, ....
this is the italian localized NG for SQL Server, and questions should be
posted in italian..

your table is defined with a primary key on the Account_Name column..
primary key implies a unique value and this is the reason you can not insert
a duplicate for that column's value..
try defining another primary key instead the actual one.. you could perhaps
use an artificial key, perhaps based on a numeric column with an
autogenerated value like the Identity property provides..
read further about artificial keys in
http://www.intelligententerprise.com...leID=201806814
regards
--
Andrea Montanari (Microsoft MVP - SQL Server)
http://www.asql.biz http://www.hotelsole.com
DbaMgr2k ver 0.21.1 - DbaMgr ver 0.65.1 and further SQL Tools
--------- remove DMO to reply




Reply With Quote
  #5  
Old   
Chase Preuninger
 
Posts: n/a

Default Re: INSERT Statment has another prolbem. - 05-17-2008 , 08:46 AM



oh, that is what the "it" menas sorry

Reply With Quote
  #6  
Old   
Chase Preuninger
 
Posts: n/a

Default Re: INSERT Statment has another prolbem. - 05-17-2008 , 08:46 AM



oh, that is what the "it" menas sorry

Reply With Quote
  #7  
Old   
Chase Preuninger
 
Posts: n/a

Default Re: INSERT Statment has another prolbem. - 05-17-2008 , 08:46 AM



oh, that is what the "it" menas sorry

Reply With Quote
  #8  
Old   
Ed Prochak
 
Posts: n/a

Default Re: INSERT Statment has another prolbem. - 05-19-2008 , 04:07 PM



On May 17, 7:48 am, "Andrea Montanari" <andrea.sql... (AT) virgilio (DOT) it>
wrote:
Quote:
hi,

Chase Preuninger wrote:
I got it to work but now I can figure out why I can't insert another
row referring to chasepreuninger. It works the first time then it
just fails.

CREATE TABLE Accounts (Account_Name VARCHAR(100) PRIMARY KEY, ....

this is the italian localized NG for SQL Server, and questions should be
posted in italian..

your table is defined with a primary key on the Account_Name column..
primary key implies a unique value and this is the reason you can not insert
a duplicate for that column's value..
try defining another primary key instead the actual one.. you could perhaps
use an artificial key, perhaps based on a numeric column with an
autogenerated value like the Identity property provides..
read further about artificial keys inhttp://www.intelligententerprise.com/showArticle.jhtml?articleID=2018...
regards
--
Andrea Montanari (Microsoft MVP - SQL Server)http://www.asql.biz http://www.hotelsole.com
DbaMgr2k ver 0.21.1 - DbaMgr ver 0.65.1 and further SQL Tools
--------- remove DMO to reply
I am curious why you reference Joe's article but immediately suggest
an artificial key a the solution. The fact is, he already has an
artificial key (NOTE_ID). But if I were to change this I would change
the PK on the NOTES table to
note_owner, note_title, note_id
This seems a more natural key and it allows multiple note entries per
title and it allows different authors (owners) to contribute to the
same topic (title).

ED


Reply With Quote
  #9  
Old   
Ed Prochak
 
Posts: n/a

Default Re: INSERT Statment has another prolbem. - 05-19-2008 , 04:07 PM



On May 17, 7:48 am, "Andrea Montanari" <andrea.sql... (AT) virgilio (DOT) it>
wrote:
Quote:
hi,

Chase Preuninger wrote:
I got it to work but now I can figure out why I can't insert another
row referring to chasepreuninger. It works the first time then it
just fails.

CREATE TABLE Accounts (Account_Name VARCHAR(100) PRIMARY KEY, ....

this is the italian localized NG for SQL Server, and questions should be
posted in italian..

your table is defined with a primary key on the Account_Name column..
primary key implies a unique value and this is the reason you can not insert
a duplicate for that column's value..
try defining another primary key instead the actual one.. you could perhaps
use an artificial key, perhaps based on a numeric column with an
autogenerated value like the Identity property provides..
read further about artificial keys inhttp://www.intelligententerprise.com/showArticle.jhtml?articleID=2018...
regards
--
Andrea Montanari (Microsoft MVP - SQL Server)http://www.asql.biz http://www.hotelsole.com
DbaMgr2k ver 0.21.1 - DbaMgr ver 0.65.1 and further SQL Tools
--------- remove DMO to reply
I am curious why you reference Joe's article but immediately suggest
an artificial key a the solution. The fact is, he already has an
artificial key (NOTE_ID). But if I were to change this I would change
the PK on the NOTES table to
note_owner, note_title, note_id
This seems a more natural key and it allows multiple note entries per
title and it allows different authors (owners) to contribute to the
same topic (title).

ED


Reply With Quote
  #10  
Old   
Ed Prochak
 
Posts: n/a

Default Re: INSERT Statment has another prolbem. - 05-19-2008 , 04:07 PM



On May 17, 7:48 am, "Andrea Montanari" <andrea.sql... (AT) virgilio (DOT) it>
wrote:
Quote:
hi,

Chase Preuninger wrote:
I got it to work but now I can figure out why I can't insert another
row referring to chasepreuninger. It works the first time then it
just fails.

CREATE TABLE Accounts (Account_Name VARCHAR(100) PRIMARY KEY, ....

this is the italian localized NG for SQL Server, and questions should be
posted in italian..

your table is defined with a primary key on the Account_Name column..
primary key implies a unique value and this is the reason you can not insert
a duplicate for that column's value..
try defining another primary key instead the actual one.. you could perhaps
use an artificial key, perhaps based on a numeric column with an
autogenerated value like the Identity property provides..
read further about artificial keys inhttp://www.intelligententerprise.com/showArticle.jhtml?articleID=2018...
regards
--
Andrea Montanari (Microsoft MVP - SQL Server)http://www.asql.biz http://www.hotelsole.com
DbaMgr2k ver 0.21.1 - DbaMgr ver 0.65.1 and further SQL Tools
--------- remove DMO to reply
I am curious why you reference Joe's article but immediately suggest
an artificial key a the solution. The fact is, he already has an
artificial key (NOTE_ID). But if I were to change this I would change
the PK on the NOTES table to
note_owner, note_title, note_id
This seems a more natural key and it allows multiple note entries per
title and it allows different authors (owners) to contribute to the
same topic (title).

ED


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.