Modifying database in Access with query by insert? - sql

Currently I am modifying my database tables with query SQL and I just have to insert a new row into the table but I can't seem to make my query run and at the moment my code reads:
INSERT INTO Facility( facname)
Values ('Swimming Pool')
Is there a step within the SQL I am missing or something for I genuinely can not figure it out. Thank you.

You need to execute it:
CurrentDb.Execute "Insert Into Facility (facname) Values ('Swimming Pool')"

Related

Sql create trigger

I would like to create a trigger which bans the user to insert value at two fields, but my code is totally wrong.There is no way to do it from constraints.Any ideas?
The DBMS is microsoft sql server 2014.My goal is the fields A and B of the table T not having both of them values at the same line,but only one of them.

Write SQL Cursor to populate all the missing rows on the extension table.

I am trying to update a table from one column to another column and once I executed the script, discovered that not all the rows updated. I was told I needed to write a SQL cursor to populate all missing rows on another table. Issue is, I am not sure how to form a cursor statement. All the how - tos I am reading are rather vague and don't explain anything. Would anyone have some basic hints on this?
Thanks!
Why do you need a cursor? If you want to insert missing tables from one table to another refer to the following post... Insert missing records from one table to another using mysql

SQL stored procedure failing in large database

I have a particular SQL file in which i copy all contents from on table in a database to another table in another database.
The traditional INSERT statements are used to perform the same operation. However this table has 8.5 Million records and it fails. The queries succeed with a smaller database.
Also in when i run the select * query for that particular table the SQL query express shows out of memory exception.
In particular there is one table that has some many records. So this table alone i want to copy from the old Db to the new Db.
What are alternate ways to achieve this?
Is there any quick work around by which we can avoid this exception and make the queries succeed?
Let me put it this way. Why would this operation fail when there are a lot of records?
I don't know if this counts as "traditional INSERT", but have you tried "INSERT INTO"?
http://www.w3schools.com/sql/sql_select_into.asp

Multiple inserts in one SQL query

DB: SQL server
I am using the below construct for inserting multiple records into a table. I am receiving the data (to be inserted) from other DB.
Insert into table1
select '1','2' UNION ALL
select '3','4' UNION ALL
select '5','6';
would there be any other chance in doing inserts in less turn around time. Its also been executed as a web request. I guess bulk insert would not fit here, as I don't have the data in a file to do a bulk insert.
Any suggestions please..
If the source database is also a SQL Server, you could add a linked server and:
insert table1 select * from linkedserver.dbname.dbo.table1
If you're inserting from .NET code, the fastest way to insert multiple rows is SqlBulkCopy. SqlBulkCopy does require DBO rights.
That is actually the best multiple insert I have ever seen. Just be careful to SQL injections, always use CommandParameters in ASP.NET or use mysql_real_escape in MySQL.
I looked into this recently, coming from MySQL and expecting the syntax from cularis' answer, but after some searching all I could find is the syntax you posted in your answer.
Edit: Looks like cularis removed his answer, he was talking about the INSERT INTO x VALUES (1, 2), (3, 4); syntax.
If you are using SQL Server 2008 and stored procedures, you could always make use of table valued parameters:
http://www.sqlteam.com/article/sql-server-2008-table-valued-parameters
It then becomes an INSERT INTO ... SELECT * FROM ...
This would help against injection problems. Not sure if this is possible with parameterised SQL.

Insert and update in the same transaction

I have heard you can not insert a row first and immediately update it in next statement in the same transaction in SQL Server? But I have been doing that (SQL Server 2005) and my results show its been done. Am I missing something or doing something stupid here? Please enlighten. Thanks.
From my experience insert and update in the same query may result in locked queries if the amount of inserts are relatively high. I'd consider creating triggers on insert and modify values before inserting them. Not sure how relevant this approach would be in your case. But having said that, it is definitely possible to do insert and update in the same query.