sql-update

Adding a constraint to prevent duplicates in SQL Update Trigger

▼魔方 西西 提交于 2020-01-30 09:15:14
问题 We have a user table, every user has an unique email and username. We try to do this within our code but we want to be sure users are never inserted (or updated) in the database with the same username of email. I've added a BEFORE INSERT Trigger which prevents the insertion of duplicate users. CREATE TRIGGER [dbo].[BeforeUpdateUser] ON [dbo].[Users] INSTEAD OF INSERT AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON;

Update two different rows in one line of SQL

二次信任 提交于 2020-01-30 05:50:09
问题 Say I have a table called example as: [abc] | [def] --1---|-qwerty- --2---|-asdf--- What I am wanting to do is update both columns in one SQL query (using only one UPDATE). UPDATE example SET def = 'foo' where abc = '1' UPDATE example SET def = 'bar' where abc = '2' The above is what I am wanting to achieve but in one line of sql (using MySQL). I know you can do this like UPDATE example SET def 'foo', SET def = 'bar' but I'm not sure how you can do this with two different where statements.

Solve query sql with rails

微笑、不失礼 提交于 2020-01-26 04:39:04
问题 I need that when I create a Historic do it: Table historic id authorization_origin_id 1 2 2 3 How you see in image bellow This is my new.html.erb <%= simple_form_for(@refinancing) do |f| %> <div class="form-inputs"> <%= f.hidden_field :employee_id, value: @employee.first.id %> <%= f.input :contract_number %> </div> <h3>Reserved value</h3> <table class="table table-condensed table-bordered table-striped"> <thead> <th>Authorization id</th> <th>Contract number</th> </thead> <% @authorizations

update statement not executing

此生再无相见时 提交于 2020-01-25 12:29:12
问题 I am trying to write an UPDATE query that can check for a null value in one of the fields. I have three conditions, two are mandatory, of three fields. itemCode and itemCheckDigit will always exist, itemSuffix is possibily Null. There may be multiple records where itemCode and itemCheckDigit together are equal to other records, itemSuffix is the unquie identifier, only one instance will exist though where itemSuffix is Null and it will never be duplicated. UPDATE item SET itemImageFileName =

Copy SEVERAL Column Values from One table into Another Matching IDs - SQLite

若如初见. 提交于 2020-01-25 08:04:07
问题 I'm elaborating on this question (Copy Column Value from One table into Another Matching IDs - SQLite) by adding an extra challenge. The idea is to copy the value of several columns from one table to another when an id is matching. The aforementioned question addresses how to copy the content of one column when a matching id is found. Here the code as posted by @scaisEdge: UPDATE t1 SET value = ( SELECT value FROM t2 WHERE t1.ID = t2.ID) But what if we want to update several columns from that

Copy SEVERAL Column Values from One table into Another Matching IDs - SQLite

怎甘沉沦 提交于 2020-01-25 08:04:03
问题 I'm elaborating on this question (Copy Column Value from One table into Another Matching IDs - SQLite) by adding an extra challenge. The idea is to copy the value of several columns from one table to another when an id is matching. The aforementioned question addresses how to copy the content of one column when a matching id is found. Here the code as posted by @scaisEdge: UPDATE t1 SET value = ( SELECT value FROM t2 WHERE t1.ID = t2.ID) But what if we want to update several columns from that

Syntax error in update using C# inputting data into an existing row

谁说我不能喝 提交于 2020-01-25 06:57:26
问题 I am having problem with my code with the update query it shows the error syntax error in update statement. I would like to insert in data into an existing row with the columns already created. private void save_care_Click(object sender, EventArgs e) { if (textBox2.Text=="") { //Checking if workorder exist in database connection.Open(); OleDbCommand checkrecord = new OleDbCommand("SELECT COUNT(*) FROM [c# barcode] WHERE ([Workorder] = @workorder)", connection); checkrecord.Parameters

Update with CTE does not recognize column names in the set clause

时光总嘲笑我的痴心妄想 提交于 2020-01-25 05:41:06
问题 I need to update an existing table with data from another. My CTE is giving me correct result, but when I'm trying to update with the CTE SSMS complains on Msg 102, Level 15, State 1, Line 13 Incorrect syntax near '.'. or Invalid column names at the lines below: set cm.Action.Identifier_fk = ID set cm.ActionRequestedAction = Action set cm.Action.apartment_fk = apartment_fk This is the code: Use DB; GO with CTE (ID,Action,Identifier_fk,apartment_fk) AS (select a.ID, a.Action, b.Identifier_fk,

SQL Update Maria DB with Prepared Statement

非 Y 不嫁゛ 提交于 2020-01-25 03:49:07
问题 Please help.. I have search it. But I still don't know where is my fault. Maybe I just miss something. Here is the error : com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '?, ID_JABATAN=?, TANGGAL_MASUK=?, TANGGAL_KELUAR=?, ID_JENIS_KARYAWAN=? WHERE ID' at line 1 And this is my code : try { DBConnection knk = new DBConnection(); Connection conn =

Update Multiple Rows in one PHP

妖精的绣舞 提交于 2020-01-21 10:27:22
问题 I have three rows with three columns in one table id type value 1 gold 1000.00 2 silver 32.21 3 platinum 1500.00 I have a form on my page with three inputs to fill in the updated values and am using ajax to send those values to update_values.php The code below works, but I am curious as to whether there is a more efficient / proper way of doing this. Thanks in advance for the knowledge-boost! PHP //Pull data from settings update $gold=$_POST['gold']; $silver=$_POST['silver']; $plat=$_POST[