THERE IS NO TRIGGER ON THIS TABLE.
I'm facing strange behaviour of sql server. One of the table column value not updating.
Here is the query and output:
Now if I execute the update statement, it executes successfully:
As per update statement all the clientId values should be 10, but it still remains 2. Here the select query result after executing update statement:
I really don't find any possible issue of this behaviour. Please help to solve this puzzle.
This might helpfully to help me:
SQL Server 2012 Express
Table:
Schema:
Table schema
If I rename the column name clientId to clientId2 or anything then update works. But if I rename the changed column name to clientId with udpated value then the updated values become 2 again.
If I keep the columne name same but table name change to Company2 or anything then then clientId values update fine.
https://raw.githubusercontent.com/codenamejakir/Demo-Video/master/sqldemo.swf
With transaction: https://raw.githubusercontent.com/codenamejakir/Demo-Video/master/SqlLive.swf
Overall I have noticed that if the table name "Company" and column name "ClientId" then column value not updating.
Thanks.
Related
New to sql statements etc and I have an issue with what i am doing using squirrelSQL on linux machine
I Created a table and used the following sql statements:-
INSERT INTO FIRSTTABLE VALUES
(11,'TEN','STEVE'),(21,'TWENTY','JO'),(31,'THIRTY','KIDS')
ALTER TABLE FIRSTTABLE
ADD SURNAME VARCHAR(15);
this works fine however when i attempt to insert data/values into the the surname row i keep experiencing errors, the SQL statement i am using is:-
INSERT INTO FIRSTTABLE (SURNAME)
VALUES ('THOMAS'),('THOMAS'),('THOMAS'),('THOMAS');
This particular statement returns the following error:-
Error: Column 'ID' cannot accept a NULL value.
SQLState: 23502
ErrorCode: 30000
I only wish to add data/values into the surname column,after creating a new column with the alter table statement, i have tried many different combinations including using a SELECT statement prior to the INSERT statement above which also gives errors any guidance will be greatly appreciated,
You are inserting into Surname, without assigning a value to the other fields. You are getting this error message because ID is blank, and should not.
Understand that INSERT creates new rows. If you wish to modify existing rows, use UPDATE
In this case you could use UPDATE FIRSTTABLE SET SURNAME='THOMAS';
Omitting the WHERE clause affects all the fields in the table.
Hope it helps, and good luck in your learning process!
The approach is wrong, you need to:
UPDATE FIRSTTABLE SET SURNAME='THOMAS' WHERE ID IN (11, 21, 31)
Inserting will add a new row to the table. So you need to update a row using
UPDATE FIRSTTABLE SET SURNAME="THOMAS" WHERE ID=11
I need to do updates over a table that contains over 600M lines on sql server, and this table does not contain the identity column, this is how it works by far :
UPDATE myTable set myBitColmun=1 where key='specifickey'
This kind of query takes over 1minute to update this specific line. And imagine the time needed to do updates on the whole table. And I need to do this kind of updates on my table everytime possible.
My question is : can identity column help perform update statement ?
alter table myTable
add id int identity(1,1)
and change my previous query:
UPDATE myTable set myBitColmun=1 where id=specificId
I am trying to update a table value from another table. I want to update pstatus from productcode.
Here is my code (which gives no error and results 0 rows):
UPDATE pstatus
SET code=(select code FROM productcode)
besides this, I can't re-run any update in sql - it gives no error, but returns 0 rows (I have more than 5 rows in productcode table).
In this case you have a two problem
you say you dont have any rows in pstatus if no record in table how can table row update ?
your inner query select code FROM productcode return more then one row then how sql decide to set with value in wich field?
An update statement doesn't return rows. You should have used something more like
Update pstatus
Set code=a.code
from productcode a
where a.*somekeyfield* = *value*
You have to determine which single record from productcode you wish to use as the basis for the update. What somekeyfield should be is something you need to determine.
An update statemend doesn't add records, it only updates records that already exist in the table.
The update query does actually udpate all the records in the table, but as there are no records, the number of updated records is zero.
If you want to add records, you should use an insert query instead:
insert into pstatus (code)
select code from productcode
I am trying the following code.
String sym=request.getParameter("symbol");
Statement st1=con.createStatement();
String symIns="UPDATE "+tblname+" SET Symbol='+sym+'";
int m=st1.executeUpdate(symIns);
if(m==0)
out.println("m is zero");
else
if(m!=0)
out.println("Inserted");
I am receiving the values of sym and tblname from previous page.But After executing this code it is printing m as zero and hence not updating the table. This code is not working for the table which does not have any record(contain only null values). But working for the table which have some records in it. I have also tried to execute it directly in the database. It is showing query executed successfully , but giving message as (0 row(s) affected). This is the query which is successfully running in the database.`
UPDATE six SET SYMBOL='eq' WHERE SYMBOL='be';
As I said it is working for this table and this table is having value for SYMBOL column as 'be'.
The query is behaving correctly. If you have matching records, it will update the rows.
So, In your query UPDATE six SET SYMBOL='eq' WHERE SYMBOL='be';, It will update the six table where you have rows with field value 'be'. But It will not update where you have NULL.
The query will execute but does not update any records and thus returns zero rows affected.
So, If you want to update rows which contains NULL as field value.
Add IS NULL
UPDATE six SET SYMBOL='eq' WHERE SYMBOL IS NULL
I'm using insert-/update triggers to update a second table's column Price.
The insert trigger seems to work perfectly, but when I try to change a single record in SSMS, I get an error:
The row value(s) updated or deleted either do not make the row
unique or they alter multiple rows(2 rows).
This is my update-trigger:
CREATE TRIGGER [dbo].[trgUpdateMasterData] ON [dbo].[tabSparePartMasterData_Temp]
AFTER UPDATE
AS
UPDATE tabSparePart
SET Price = MD.Price
FROM tabSparePart INNER JOIN
(
SELECT inserted.[Material Number (SAP)] AS MaterialNumber, inserted.Price
FROM inserted
GROUP BY [Material Number (SAP)], inserted.Price
) MD
ON tabSparePart.SparePartName = MD.MaterialNumber
I need to group by Material-Number because there are redundant rows inserted into table tabSparePartMasterData_Temp which i'm only using to update the Sparepart-Price in tabSparePart. But i assumed that the group by would sort out the duplicates(Price is same for any duplicate).
It's possible that the inserted/updated records' MaterialNumber is not available in tabSparepart. In this case this record should be "skipped". Does the INNER JOIN takes that into account?
Try adding SET NOCOUNT ON to the trigger
This error doesn't look like a SQL error and I'm guessing the client code is getting confused by the 2nd update in the trigger.
Edit: this error can be caused by the data grid view in SSMS being silly.
This isn't a SQL message as I thought: it is an SSMS being stupid message
See these which all says "learn to write SQL"
http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/dealing-with-the-row-value-s-updated-or (Less than dot blog)
Trigger that modifies multiple rows on diffrent table then it was invoked on in SQL Server 2005
SSMS permits duplicate records in a table, but not subsequent updates
Saying that, there is a KB article about a bug in SQL Server 2005...