Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Problem with insert , cannot insert NULL value

Author  Topic 

g_p
Starting Member

48 Posts

Posted - 2007-01-30 : 08:36:00
Good evening,

I have created a table like this:

create table Teacher(tid integer,
fname varchar(20),
lname varchar(30),
primary key(tid));

Well i insert many Teachers uning : insert into values ... etc.
These inserts are being placed in an sql file named insert.sql.
All the insertions are fine.

Now I'm trying to insert another teacher using another file e.g. my_insert.sql and it says cannot insert NULL into teacher tid etc.

Why does this happen,in my my_insert.sql file all the filds of the tid are filled with non null values?

What's going wrong?

Thanks, in advance!

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-01-30 : 08:37:12
Column TID is PRIMARY KEY, it will not allow NULL values nor duplicate values.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

g_p
Starting Member

48 Posts

Posted - 2007-01-30 : 08:45:25
quote:
Originally posted by Peso

Column TID is PRIMARY KEY, it will not allow NULL values nor duplicate values.


Peter Larsson
Helsingborg, Sweden



Thanks, for replying,
you are right about the NULL values but all my insertions contain a tid which is not null
I dunno what's going wrong!
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-01-30 : 08:48:45
post your my_insert.sql here


KH

Go to Top of Page

g_p
Starting Member

48 Posts

Posted - 2007-01-30 : 08:53:39
quote:
Originally posted by khtan

post your my_insert.sql here


KH







This is my_insert.sql(second file)

insert into Teacher values(2,'Mary','Jones');
insert into Teacher values(20,'George','George');

However,i have already inserted values using insert.sql(first file)
and then i have typed commit.

So,what's going wrong?
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-01-30 : 08:55:39
What is the first file?


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

g_p
Starting Member

48 Posts

Posted - 2007-01-30 : 08:59:11
quote:
Originally posted by Peso

What is the first file?


Peter Larsson
Helsingborg, Sweden


Well the first file contains again four insertions with different and not null tids,and the rows are created.
Then i do commit;
Then i try to insert some other values using the second file(my_insert.sql)
and it says ays cannot insert NULL into teacher tid.

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-01-30 : 09:02:23
If the TID is larger than Integer, a NULL value will be inserted instead, that's why I asked.
But if you don't bother to be helped, so be it.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

g_p
Starting Member

48 Posts

Posted - 2007-01-30 : 09:08:13
quote:
Originally posted by Peso

If the TID is larger than Integer, a NULL value will be inserted instead, that's why I asked.
But if you don't bother to be helped, so be it.


Peter Larsson
Helsingborg, Sweden


Well i didn't paste the inserts cause all the tids are 12,25,26, small numbers.My first file works.
My second file doesn't work
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-01-30 : 09:14:36
Well, try to paste individual insert statements from the second file and run them one-by-one and see which one is giving error.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

g_p
Starting Member

48 Posts

Posted - 2007-01-30 : 09:43:08
quote:
Originally posted by harsh_athalye

Well, try to paste individual insert statements from the second file and run them one-by-one and see which one is giving error.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"


The individual inserts work,but the file doesn't work
Thanks!
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-01-30 : 10:16:07
If all the individual statements in the file work but the file as a whole doesn't work and the file contains only the insert statements you mentioned here, then this whole thing doesn't make sense at all.

BTW, why are you executing commit after first file? Is there corresponding BEGIN TRANSACTION ?

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

g_p
Starting Member

48 Posts

Posted - 2007-01-30 : 17:01:00
quote:
Originally posted by harsh_athalye

If all the individual statements in the file work but the file as a whole doesn't work and the file contains only the insert statements you mentioned here, then this whole thing doesn't make sense at all.

BTW, why are you executing commit after first file? Is there corresponding BEGIN TRANSACTION ?

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"



Well i do commit in order for the database to be informed.
If i don't do so the database doesn't show the updates that have been done.
Go to Top of Page
   

- Advertisement -