I’ve got 2 tables: TimecardSetDetails, TimecardDetails TimecardSetDetails +————–+————-+————–+ | SetDetailsID | EmployeeKey | SetHistoryID | +————–+————-+—–…
Tag: sql-insert
INSERT SELECT statement with only one column for SELECT
I’m using SQL Server Management Studio 18 and I’ve got the following tables with the following columns: TableA TableB I want to do an INSERT SELECT into TableB, maybe something like the following: Basically, I just want to make an INSERT SELECT where I’m grabbing a column from another table (InternalEmplID), and then for the other columns (Month and Year),
Trigger for UPDATE runs many time on batch Updates
All of my tables have a Trigger for CRUD operations. here is a sample: If I update one row, everything works fine and trigger inserts one row in history. For example But if more than one row updated, updatedrow^2 rows will be inserted. For example 9 for 3 rows 100 for 10 rows… What is wrong with my trigger and
Redshift If TableA contains data then TRUNCATE TableB and INSERT TableA into TableB ELSE do nothing
I am trying to create a query in Redshift but I am struggling to ether create the correct logic or to get it to run full stop. I have 2 tables TableA and TableB. If TableA contains data, then wipe TableB and insert the data from TableA. Pseudo: Obviously this wont work so do I need to do something with
Couldn’t return output with SRC Key in an INSERT statement
I want the OUTPUT clause to return both the source key and the target key like below : I am having this following error : Answer To be clear, in INSERT, UPDATE, and DELETE statements, you can only refer to columns from the target table in the OUTPUT clause. In a MERGE statement you can refer to columns from both
Does sqlsrv_query limit the number of statements that can be exectuted in one query?
I am generating a SQL insert statement within a PHP for loop. The SQL string generated is a large number of individual SQL statements like this: INSERT INTO tbl VALUES(1,2,3); INSERT INTO tbl …
SQL – Violation of UNIQUE KEY constraint
I am trying to find the solution for the below query: There are declared tables @Country and @WHO (World Health Organization). Insert all possibles countries from table @Country into table @WHO. …
How to remove check constraint?
I am having difficult to remove CHECK using Alter in sql. Can anyone help me please? Answer Oracle does have an alter table … drop constraint syntax for this. But since you created an anonymous constraint, so this is tricky – because you don’t know the name of the constraint. One option is to use dynamic SQL to retrieve the
Updating sequence for primary key in postgres for a table with a lot of deletions
I have the following problem: I have a table with a lot of deletions and inserts of rows. Also I would like to assign to each of current rows in tables some id number. Currently I’m trying to do it with But if I understand correctly, sequences are monotonous and can’t go down when i delete some rows, so i
How to insert into a row, a value from other table?
I have 3 Mysql tables. A table with the classes and the labs and their id. A table with the teachers_list and their subject. A table which is going to be the schedule.** I want to randomly assign one of the physicists to one of the physics labs on my third table which is going to be the schedule. **This