sql-insert

Import Data to Existing Table

馋奶兔 提交于 2020-01-05 05:43:05
问题 How to import data to existing table in Database from another Database in sql I am trying this but not working . It is saying 'Cannot insert an explicit value into a timestamp column.' Use INSERT with a column list to exclude the timestamp column, or insert a DEFAULT into the timestamp column. Insert Into [test].[dbo].[Sample$Employee] select * from [Test1].[dbo].[Sample1$Employee] Thanks 回答1: INSERT INTO Target_Table(Column1, Column2, Column3) SELECT Column1, Column2, Column3 FROM Source

Cannot insert into table with types in SQL Server

梦想与她 提交于 2020-01-05 04:30:08
问题 I have a C# application and I use type to insert into a SQL Server table: CREATE TYPE [dbo].[taradodType] AS TABLE ( [IDP] [int] NULL, [date] [datetime] NULL, [day] [nvarchar](max) NULL, [nobatkari] [nvarchar](max) NULL, [code] [nvarchar](max) NULL ) C# code : SqlConnection sqlconn = new SqlConnection(DBsetting.Connstring); sqlconn.Open(); using (sqlconn) { try { SqlCommand cmd = new SqlCommand("InsertTaradod", sqlconn); cmd.CommandType = CommandType.StoredProcedure; SqlParameter dtparam =

MySQL How to insert new record or update a field depending on whether it exists?

空扰寡人 提交于 2020-01-04 17:26:13
问题 I am trying to implement a rating system where I keep the following two fields in my db table: rating (the current rating) num_rates (the number of ratings submitted so far) UPDATE `mytable` SET rating=((rating*num_rates)+$theRating)/num_rates, num_rates=num_rates+1 WHERE uniqueCol='$uniqueCol' the variables are from my PHP code. So, basically sometimes the row with the uniqueCol does not exist in the DB, so how can I do the above statement if the exists and if it doesn't then do something

Cannot insert the value NULL into column 'UserId'

懵懂的女人 提交于 2020-01-04 13:46:33
问题 I am getting this exception and can not figure out why: Cannot insert the value NULL into column 'UserId' This is my code: <asp:TextBox ID="FirstNameBox" runat="server" /> <br /> <br /> <asp:TextBox ID="LastNameBox" runat="server" /> <asp:SqlDataSource ID="InsertText" runat="server" ConnectionString="<%$ ConnectionStrings:DefaultConnection %>" InsertCommand="INSERT INTO UserForm (UserId,FirstName,LastName) VALUES (@UserId,@FiName,@LaName)"> <InsertParameters> <asp:ControlParameter Name=

Cannot insert the value NULL into column 'UserId'

ぐ巨炮叔叔 提交于 2020-01-04 13:43:16
问题 I am getting this exception and can not figure out why: Cannot insert the value NULL into column 'UserId' This is my code: <asp:TextBox ID="FirstNameBox" runat="server" /> <br /> <br /> <asp:TextBox ID="LastNameBox" runat="server" /> <asp:SqlDataSource ID="InsertText" runat="server" ConnectionString="<%$ ConnectionStrings:DefaultConnection %>" InsertCommand="INSERT INTO UserForm (UserId,FirstName,LastName) VALUES (@UserId,@FiName,@LaName)"> <InsertParameters> <asp:ControlParameter Name=

How to avoid code repetition with PHP SQL prepared statements?

可紊 提交于 2019-12-30 07:46:15
问题 In most examples of SQL PHP prepared statements that I see, such as: $sql = 'INSERT INTO tasks(task_name, start_date, completed_date) VALUES(:task_name, :start_date, :completed_date)'; $stmt = $this->pdo->prepare($sql); $stmt->execute([ ':task_name' => $taskName, ':start_date' => $startDate, ':completed_date' => $completedDate, ]); the field names are nearly repeated ... 4 times! once after the INSERT INTO(...) : task_name (column name in SQL) once after the VALUES(...) : :task_name once in

Postgres INSERT ON CONFLICT DO UPDATE vs INSERT or UPDATE

回眸只為那壹抹淺笑 提交于 2019-12-30 06:05:04
问题 I have stock_price_alert table with 3 columns. stock_price_id is PRIMARY KEY & also FOREIGN KEY to other table. Table definition as below: create table stock_price_alert ( stock_price_id integer references stock_price (id) on delete cascade not null, fall_below_alert boolean not null, rise_above_alert boolean not null, primary key (stock_price_id) ); I need to either: 1) INSERT record if not exist -- query 1 INSERT INTO stock_price_alert (stock_price_id, fall_below_alert, rise_above_alert)

Postgres INSERT ON CONFLICT DO UPDATE vs INSERT or UPDATE

独自空忆成欢 提交于 2019-12-30 06:04:50
问题 I have stock_price_alert table with 3 columns. stock_price_id is PRIMARY KEY & also FOREIGN KEY to other table. Table definition as below: create table stock_price_alert ( stock_price_id integer references stock_price (id) on delete cascade not null, fall_below_alert boolean not null, rise_above_alert boolean not null, primary key (stock_price_id) ); I need to either: 1) INSERT record if not exist -- query 1 INSERT INTO stock_price_alert (stock_price_id, fall_below_alert, rise_above_alert)

Postgres INSERT ON CONFLICT DO UPDATE vs INSERT or UPDATE

被刻印的时光 ゝ 提交于 2019-12-30 06:04:38
问题 I have stock_price_alert table with 3 columns. stock_price_id is PRIMARY KEY & also FOREIGN KEY to other table. Table definition as below: create table stock_price_alert ( stock_price_id integer references stock_price (id) on delete cascade not null, fall_below_alert boolean not null, rise_above_alert boolean not null, primary key (stock_price_id) ); I need to either: 1) INSERT record if not exist -- query 1 INSERT INTO stock_price_alert (stock_price_id, fall_below_alert, rise_above_alert)

Run SQL statements in PL/pgSQL only if a row doesn't exist

 ̄綄美尐妖づ 提交于 2019-12-29 09:22:36
问题 I want to do something like this in a PL/pgSQL function in Postgres 9.6: INSERT INTO table1 (id, value) VALUES (1, 'a') ON CONFLICT DO NOTHING; --- If the above statement didn't insert a new row --- because id of 1 already existed, --- then run the following statements INSERT INTO table2 (table1_id, value) VALUES (1, 'a'); UPDATE table3 set (table1_id, time) = (1, now()); However, I don't know how to determine whether the first INSERT actually inserted a new row, or whether the the ON