error message when trying to write a sequence - sql

i am trying to write the following sequence
INSERT INTO cruise (cruise_id, cruise_name)
VALUES (SEQ_CRUISE_ID.NEXTVAL, 'hawaii and back');
but when I execute it, I receive an error message. I do have privileges to execute the command. I appreciate any help and suggestions on this one

Can you give us the error message so we can have more insight into the issue? The only issue found is that this db collection might not exist. Can you confirm if table in question exists?
table: cruise

Related

Error when inserting data in ssms through "Execute Stored Procedure"

The below shown is my program:
As You can see, all the table details are correct. But when I try to run it through the "Execute Stored Procedure", the details are not entered into the table.
Rather I get a output like this:
How I can solve this?
Note: Recently had MSDB in SUSPECT, so, took my friends MSDB log and data, is that causing the problem? If yes, what can i do about that?
The error message would certainly help. A quick, easy change would be to replace
set #msg='Error'
with
set #msg= ERROR_MESSAGE();
so we can see the error.
If this isn't possible I suggest:
Run the INSERT statement manually to see what message you get
Check that the ID column is an Identity column as you don't provide the ID in the INSERT so I assume it should be
I hope this helps.

Table is automatically truncated on SQL Server

I have a really strange problem on my SQL Server.
Every night 2 tables, that I have recently created, are being automatically truncated...
I am quite sure, that it is truncate, as my ON DELETE Trigger does not log any delete transactions.
Additionally, using some logging procedures, I found out, that this happens between 01:50 and 01:52 at night. So I checked the scheduled Jobs on the server and did not find anything.
I have this problem only on our production server. That is why it is very critical. On the cloned test server everything works fine.
I have checked transaction log entries (fn_dblog), but didnt find any truncate logs there.
I would appreciate any help or hints that will help me to find out process/job/user who truncates the table.
Thanks
From personal experience of this, as a first step I would look to determine whether this is occurring due to a DROP statement or a TRUNCATE statement.
To provide a possible answer, using SSMS, right click the DB name in Object Explorer, mouse over Reports >> Standard Reports and click Schema Changes History.
This will open up a simple report with the object name and type columns. Find the name of the table(s), click the + sign to expand, and it will provide you history of what has happened at the object level for that table.
If you find the DROP statement in there, then at least you know what you are hunting for, likewise if there is no DROP statement, you are likely looking for a TRUNCATE.
Check with below query,
declare #var as varchar(max)='tblname'
EXEC sp_depends #objname =#var;
it will return number of stored procedure name which are using your table and try search for any truncate query if you have wrote by mistake.
Thanks a lot to everyone who has helped!
I've found out the reason of truncating. It was an external application.
So if you experience the same problem, my hint is to check your applications that could access the data.
I don't know if can help you to resolve the question.
I often encounter the following situations.
Look at this example:
declare #t varchar(5)
set #t='123456'
select #t as output
output:12345

How to Truncate table in DB2? Error: Not a valid Command Line Processor command

Running following statement in DB2 CLP (Command Window)
db2 "truncate table MYSCHEMA.TABLEA immediate"
DB21034E The command was processed as an SQL statement because it was not a
valid Command Line Processor command. During SQL processing it returned:
SQL0969N There is no message text corresponding to SQL error "-20356" in the
message file on this workstation. The error was returned from module
"SQLNQBE2" with original tokens "MYSCHEMA.TABLEA".
Can some please tell me what I'm doing wrong or what I'm missing? I'm trying to simply truncate from a single table and I'm getting the following error message. Not sure what I'm doing wrong. I've tried it with/without quotes, with/without schema, with/without immediate. I've also tried in Command Editor (remove db2 and quotes) and still not working. I'm using:
DB2/AIX64 9.7.9
Also, I have delete privilege as I am able to delete records but I want to truncate.
Thanks in advance!
The version of the DB2 client you're using doesn't seem to match that of the server, this is why you cannot see the actual error message for SQLCODE -20356. If you could, you'd see this:
The table MYSCHEMA.TABLEA cannot be truncated because DELETE triggers
exist for the table, or the table is the parent in a referential
constraint.
Further explanation and suggested actions can be found, as usual, in the fine manual.
ALTER TABLE MYSCHEMA.TABLEA ACTIVATE NOT LOGGED INITIALLY WITH EMPTY TABLE
or
import from /dev/null of del replace into MYSCHEMA.TABLEA
I had this problem recently too. In my case I had to do a COMMIT WORK right before TRUNCATE. This solved my problem. Please try and tell us if this helped.

Can I create a new stored procedure with error inside? [duplicate]

This question already has an answer here:
How to forcibly create stored procedure even if some error occurs?
(1 answer)
Closed 9 years ago.
This morning I try to create an stored procedure in SQL Server and I know there's error inside it but for some reasons I want to keep it and fix it in the future. But when I execute "create procedure", it returned error told me that something wrong. And I think because of this, the procedure didn't be created but I want to create this procedure even there's problem.
Any ideas?
If you are getting an error when running the CREATE statement, then you will be unable to create it. You can save it as a .SQL file and fix the error later.
This is different than an error you might get when running the procedure. There is something wrong with the create statement syntax wise, or some other issue such as SP of same name, lack of permissions to create SP's, etc. Either way, you shouldn't be able to CREATE the SP until those problems are fixed.
There's another way.
Instead of saving the .sql File.
You can comment the error part and run the Procedure.
This will store the Procedure in your DB and then you can Fix it later.

How can I log when a column is updated in SQL Server 2005?

I'm having a problem with a database, where it seems a column is updated with a wrong value. At the moment, I have no idea which program is doing this. What would be the best way to find this out? Things that could really help me are, in order of helpfulness:
The application name
the host executing the application
the exact SQL statement.
Could the transaction log help me here? Can I write a logging trigger somehow?
Help would be appreciated.
You could create a trigger and a table, along the lines of
CREATE TRIGGER TRG_foo_U On foo FOR UPDATE
AS
SET NOCOUNT ON
IF UPDATE(bar)
INSERT logtable
SELECT APP_NAME(), HOST_NAME(), SUSER_SNAME(), GETDATE(), * FROM INSERTED
GO
SQL profiler will give you this information, and I beleive you should be able to apply a filter such that you'd need to capture events on that particular object.
You could try to use the SQL Profiler to see all the activity going on against the database.