Delete from sql server 2000? - sql

I want to delete all rows from table in sql server 2000 but whenever I want to delete manually or with query it shows error. In help tab it shows ODBC error: <0s>.
My table contains some '0' values but its datatype is String. Is that's the reason for this
error.
code is:
stat2=conn.createStatement();
stat2.executeUpdate("Delete * from pat.dbo.PHPL");
"Key column information is insufficient or incorrect. Too many rows were affected by update" that's warning and when click help it shows: ODBC error: <0s>. An ODBC error has been generated. You might have deleted a record that has a foreign key value related to it, or you might have violated a check constraint. For details, refer to your ODBC documentation.

Use
Truncate Table PHPL
I think you have duplicate identities, check you are not allowing duplicates on this column.

Related

Microsoft SQL - "Invalid column name" after deleting column

I am using Azure SQL in Microsoft SQL Management studio. I firstly renamed a column called ssma$rowid to ssmarowid, then I deleted this column using
ALTER TABLE "myCoolTable" DROP COLUMN "ssmarowid";
SQL management studio prompted me that the deletion was successful, but now that I try to run any UPDATE commands on my table in different columns, I get this error message:
Invalid column name 'ssma$rowid'.
If I try to edit a cell without scripting, by right-clicking my table, then Edit top 200, I get this error message:
The data in row xxx was not committed.
Error Source: .Net SqlClient Data Provider.
Error Message: Invalid column name 'ssma$rowid'
Invalid column name 'ssma$rowid'
Invalid column name 'ssma$rowid'
Correct the errors and retry or press ESC to cancel the change(s)
The column ssma$rowid does not appear in my table at all when I run a SELECT statement, and if I explicitly try to pull the column ssma$rowid or ssmarowid SQL tells me that they don't exist.
It appears that my column has been lost in the ether somewhere, where can I start searching to find my rogue column?
Ensure the ALTER TABLE states the column between brackets like this :
ALTER TABLE [myCoolTable] DROP COLUMN [ssmarowid];

Insert statement attempted to include a duplicate key

Trying to run
INSERT INTO BOOKING_EXTRAS (BOOKING_ID, EXTRAS_, EXTRAS_PRICE) VALUES ('1','Phone call: 1.80','1.8');
in Oracle SQL Developer. Ive had it running but when I close it, then reopen it I get this error:
Error starting at line 1 in command:
INSERT INTO BOOKING_EXTRAS (BOOKING_ID, EXTRAS_, EXTRAS_PRICE) VALUES ('1','Phone call: 1.80','1.8')
Error report:
SQL Error: ORA-00001: unique constraint (COURSEWORK_XE.BOOKING_EXTRAS_PK) violated
00001. 00000 - "unique constraint (%s.%s) violated"
*Cause: An UPDATE or INSERT statement attempted to insert a duplicate key.
For Trusted Oracle configured in DBMS MAC mode, you may see
this message if a duplicate entry exists at a different level.
*Action: Either remove the unique restriction or do not insert the key.
how would I fix this? Its happening to every table I run!
You need to either clear the tables or insert new information, a database doesn't want duplicate rows because that makes it impossible to find the correct rows later.
In addition, if that BOOKING_ID (currently serves as primary key if I guess right) doesn't actually mean something for you, you can set it as AUTO INCREMENT in your schema, then afterwards you don't need to insert a value for BOOKING_ID, the system will automatically find a value which is not duplicate for you. This might save you a lot effort.
INSERT INTO BOOKING_EXTRAS (EXTRAS_, EXTRAS_PRICE) VALUES ('Phone call: 1.80','1.8');
If your unique column is being populated by a sequence, check to make sure that your sequence has the same 'last value' as your highest-value unique column.
I just encountered a problem where the sequence had a 'last value in' that was much lower than the highest value in my unique column. The DBA ran a script to update the sequence to what the number should have been, and my error went away.
Now to find out why the sequence was so wrong...

cannot delete and update records on access linked table

I have access database called road.mdb.
Inside road.mdb, I have a linked SQL table and
the table name is student.
I can insert records using query design in MSAccess
But I cannot update nor Delete
when run delete query below, the error is: could not delete from specified table
delete from student where studentid=303;
and when I run update query below, the error is: Operation must use an updateable query
update student set Name='BOB' where studentid= 303;
I have full access to the sql database and I can run the query OK using sql management studio.
Is it impossible to delete and update using query design inside MSaccess??
The weird thing is I can insert new records using query design inside MSaccess
thank you
I SOLVED this by adding primary key to the SQL table and re linked the table to ACCESS
Thanks everyone...
In the case that you can't manipulated the table on SqlServer, you can get around the problem by telling Access which/s column/s are meant to be the primary key. This is done on the last step of creating a Linked table, the window title is "Select Unique Record Identifier".
You will find that the following steps will most likely solve your problem:
In SQL Server: set a primary key on the table you are working with and make sure the primary key is of type int, not bigint as Access will not properly deal with bigint data type.
In SQL Server: refresh the table.
In MS Access: re-link the table.
(You can easily check if 'things are OK' afterwards by adding a record to the SQL Server table and accessing it through the MS Access linked table. When all is OK you should not see #Deleted when viewing the data from MS Access side.)
Hope it helps ;-)
In my case, the linked table only had keys. I had to modify one of the keys to be a primary key and then I could truncate truncate the table via a DELETE table.* FROM table via access.
In my case the problem was a BIT column. I think the problem occurs when the the bit column contains a NULL value.
To resolve the issue, I either deleted the entire column, or set a default value.

Access Database - Auto INSERT\UPDATE - Qt4

In a registration software made with Qt4, I open an Access .mdb database, update it with the user-provided fields.
It has currently a table clients with six fields:
CustomerNumber, FullName, CNICNumber, ResidentialAddress, ResidentialPhoneNumber, MobileNumber
where CustomerNumber is primary key and a number, while all others are text. There are a few records present. But when another record with same CustomerNumberis tried to be inserted, there is an error:
QODBCResult::exec: Unable to execute
statement: "[Microsoft][ODBC Microsoft
Access Driver] The changes you
requested to the table were not
successful because they would create
duplicate values in the index, primary
key, or relationship. Change the data
in the field or fields that contain
duplicate data, remove the index, or
redefine the index to permit duplicate
entries and try again."
"[Microsoft][ODBC Microsoft Access
Driver] The changes you requested to
the table were not successful because
they would create duplicate values in
the index, primary key, or
relationship. Change the data in the
field or fields that contain duplicate
data, remove the index, or redefine
the index to permit duplicate entries
and try again." "QODBC3: Unable to
execute statement"
I then found the UPDATE query, but the following code gives another error:
query.exec("UPDATE clients"
"SET FullName='"+cname+"', CNICNumber='"+cnic+"', ResidentialAddress='"+caddress+"', ResidentialPhoneNumber='"+cphone+"', MobileNumber='"+cmobile+"'"
"WHERE CustomerNumber="+cnumber+";");
The variables cname, cninc, caddresss, cphone, cmobile, cnumber are strings with values. But the error with the above code is:
QODBCResult::exec: Unable to execute
statement: "[Microsoft][ODBC Driver
Manager] Function sequence error"
"[Microsoft][ODBC Driver Manager]
Function sequence error" "QODBC3:
Unable to execute statement"
What is the solution to this, i.e. how to insert a new record when the primary key is not present but update existing record with same primary key?
You are missing spaces. The actual command you are executing is equivalent to
query.exec("UPDATE clientsSET Fullname...
there is no such table as clientsSET.
Here is what you intended
query.exec("UPDATE clients"
" SET FullName='"+cname+"', CNICNumber='"+cnic+"', ResidentialAddress='"+caddress+"', ResidentialPhoneNumber='"+cphone+"', MobileNumber='"+cmobile+"'"
" WHERE CustomerNumber="+cnumber+";");
If these are user-input values you are vulnerable to SQL injection. You need to be careful to scrub all the string values (eg. replace all ' with '').
What is the solution to this, i.e. how
to insert a new record when the
primary key is not present but update
existing record with same primary key?
This is known informally as an UPSERT. See this answer that relates to Access.
query.exec("UPDATE clients"
...CNICNumber='"+cnic+"', ...
My guess would be that CNICNumber shouldn't have single quotes around it.
...CNICNumber="+cnic+", ...
But it's impossible to tell for sure without knowing your table structure.
Can you try with:
+ " SET FullName='"+cname+ ...
+ " WHERE CustomerNumber="+cnumber+";");
in the second and third row?

How do you find the RULE associated to a column?

I have a SQL Database that has some Table and in that table there's a Column.
I'm using NHibernate to do an update to a record, when I get this exception saying I'm violating some RULE on the column.
I do some research to find out there's a RULE associated with that column in the database, but I have no idea how to find this rule, see what it does, etc.
Does anyone know how to show the rules for a column? Or just all the rules in the database, anything to get me heading in the right direction.
** EDIT **
The exact error message is:
A column insert or update conflicts
with a rule imposed by a previous
CREATE RULE statement. The statement
was terminated. The conflict occurred
in database '[MYDB]', table
'[MYTABLE]', column '[MYCOLUMN]'.
Do sp_help TableName. It will return a number of resultsets, one of which (the 7th one) shows the contraints on the table.
You can also inspect the other resultsets for not nullable columns, identity columns, etc.
Look in SQL Server Management Studio.
Connect to the SQL Server, browse to the database, then open the programmability section.
Go to the rules folder, and that will list all the rules in the database.