HSQLDB - Check existing schema for reserved SQL keywords - hsqldb

After executing SET DATABASE SQL NAMES TRUE the database doesn't allow me to create, for example, a column called DAY.
Since I executed the statement on a database catalog that I had already been working on for a while I would like to know if there's a way to check an existing schema for these violations.

You can make a copy of the database and edit the .script file of the copy to change the existing statement SET DATABASE SQL NAMES FALSE to TRUE. When you open the copy, the engine will stop loading the script and report an error if it encounters a reserved name used for a database object. You can edit the disallowed names and try again until there is no error.

Related

Updating a Field Value in a foreign DB's table in ms-Access using SQL

Assume I have two Access files "Old" and "New" with the same structure. I want to Export (using SQL) a value from a field in "Old" db to its corresponding place in "New" db, initiating the SQL command from "Old" db.
To be more specific, the table name is "INFO", and the field name is "IBAN", and the exporting will be to the same ID value which is 1.
I googled and read some older questions in here, and found some similar request but with a key difference is that the order comes from "New" db, in other words, they are importing the value.
So, is what I am asking even possible? Thanks in advance.
Options:
set a link in OldDb that connects to table in NewDb and run an UPDATE action
VBA example, assuming the two files are on same computer C drive:
CurrentDb.Execute "UPDATE INFO IN 'C:\folder path\New.accdb' SET [IBAN]=something WHERE ID=1"

changing database name in sql server script

I created a schema script for an sql server database called test.
I want to execute this script in the same server where the test database is found, but for sure with different name, suppose test2.
when I opened the scripts, it starts by CREATE DATABASE [test] and the name test is used many times in the script.
so how to safely change database name in the script without affecting the original database?
Note: changing name by just replacing it's name is not a solution because it's name is a part of many procedures and functions
No need to use database name in each and every query. Just use
USE [Database_Name]
in the above of the script file, then it will consider the database for the entire script until you specify another database name inside the script.
Eg:-
USE My_Database_1
Script_1
Script_2
.
.
Script_n
--Another Database if required
USE My_Database_2
Script_1
Script_2
.
.
Script_n

Transfer data from one database to another database

How to fetch the data from one database and insert in to another database table? I can't to do this. Please help me in transferring data from one to another.
There are several ways to do this, below are two options:
Option 1
- Right click on the database you want to copy
Choose 'Tasks' > 'Generate scripts'
'Select specific database objects'
Check 'Tables'
Mark 'Save to new query window'
Click 'Advanced'
Set 'Types of data to script' to 'Schema and data'
Next, Next
You can now run the generated query on the new database.
Option 2
Right click on the database you want to copy
'Tasks' > 'Export Data'
Next, Next
Choose the database to copy the tables to
Mark 'Copy data from one or more tables or views'
Choose the tables you want to copy
Finish
Example for insert into values in One database table into another database table running on the same SQL Server
insert into dbo.onedatabase.FolderStatus
(
[FolderStatusId],
[code],
[title],
[last_modified]
)
select [FolderStatusId], [code], [title], [last_modified]
from dbo.Twodatabase.f_file_stat
For those on Azure, follow these modified instructions from Virus:
Open SSMS.
Right-click the Database you wish to copy data from.
Select Generate Scripts >> Select Specific Database Objects >> Choose the tables/object you wish to transfer.
strong text
In the "Save to file" pane, click Advanced
Set "Types of data to script" to Schema and data
Set "Script DROP and CREATE" to Script DROP and CREATE
Under "Table/View Options" set relevant items to TRUE. Though I recommend setting all to TRUE just in case. You can always modify the script after it generates.
Set filepath >> Next >> Next
Open newly created SQL file. Remove "Use" from top of file.
Open new query window on destination database, paste script contents (without using) and execute.
if both databases are on same server and you want to transfer entire table (make copy of it) then use simple select into statement ...
select * into anotherDatabase..copyOfTable from oneDatabase..tableName
You can then write cursor top of sysobjects and copy entire set of tables that way.
If you want more complex data extraction & transformation, then use SSIS and build appropriate ETL in it.
You can use visual studio 2015. Go to Tools => SQL server => New Data comparison
Select source and target Database.
You can backup and restore the database using Management Studio.
Again from Management Studio you can use "copy database".
you can even do it manually if there is a reason to do so. I mean manually create the target db and manually copying data by sql statements...
can you clarify why you ask this? Is it that you dont have expierience in doing it or something else?
There are multiple options and depend on your needs.
See the following links:
Copying Data Between Servers
Copy tables from one database to another in SQL Server.
These solutions are working in case when target database is blank.
In case when both databases already have some data you need something more complicated http://byalexblog.net/merge-sql-databases
This can be achieved by a T-SQL statement, if you are aware that FROM clause can specify database for table name.
insert into database1..MyTable
select from database2..MyTable
Here is how Microsoft explains the syntax:
https://learn.microsoft.com/en-us/sql/t-sql/queries/from-transact-sql?view=sql-server-ver15
If the table or view exists in another database on the same instance of SQL Server, use a fully qualified name in the form database.schema.object_name.
schema_name can be omitted, like above, which means the default schema of the current user. By default, it's dbo.
Add any filtering to columns/rows if you want to. Be sure to create any new table before moving data.
Doing this programmatically between two different databases could involve a scheduled job using a linked server. But linked servers require DBA-level knowledge to set up. If you can't use a linked server, just write a program that 1. Reads a row from the source table and 2. Inserts it into the target table. The programmer just needs to use a connection string that has INSERT privileges into the target database table. I have solved this problems using both approaches.

Applying changes easily in Access Database

I have got a backup of a live database (A copy of an ACCDB format Access database) in which I've worked, added new fields to existing tables and whole new tables.
How do I get these changes and apply that fast in the running database?
In MS SQL Server, I'd right-click > Script Table As > Alter To, save the query and run it wherever I desire, is there an as easy way as that to do it in an Access Database ?
Details:
It's an ACCDB MS-Access database created on Access 2007, copied and edited in Access 2007, in which I need to get some "alter" scripts to run on the other database so that it has all the new columns and tables I've created on my copy.
For new tables, just import them from one database into the other. In the "External Data" section of the ribbon, choose the Access icon above "Import". That choice starts an import wizard to allow you to select which objects you want imported. You will have a choice to import just the table structure, or both structure and data.
Remou is right that you can use DDL ALTER TABLE statements to add new columns. However, DDL might not support every feature you want for your new columns. And if you want not just the empty columns added, but also also any data from those new columns, you will probably need to run UPDATE statements to get it into your new columns.
As far as "Script Table As", see if OmBelt's Export Table to SQL tool for MS Access can do what you want.
Edit: Allen Browne has sample ALTER TABLE statements. See CreateFieldDDL and the following one, CreateFieldDDL2.
You can run DDL in Access. I think it would be easiest to run the SQL with VBA, in this case.
There is a product called DbWeigher that can compare Access database schemas and synchronize them. You can get a free trial (30 days). DbWeigher will write a script of all schema differences and write it out as DDL. The script is thorough and includes relationships, indexes, validation rules, allow zero length, etc.
A free tool from the same developer, DBWConsole, will let you execute a DDL script against any Access database. If you wrote your own DDL scripts this would be an easy way to apply the changes to your live database. It even handles some DDL that I don't know how to process in VBA (so it must be magic). DBWConsole is included if you downloaded the trial version of DBWeigher. Be aware that you can't make schema changes to a table in a shared Access database if anyone has the table open.
DbWeigher creates a script of all differences between the two files. It can be a lot to manually parse through if you just want a few of the changes. I built a parser for DbWeigher script files so they could be filtered by table, to extract just the parts I wanted. I contacted the DbWeigher author about it but never heard back. It's safe to say that I have no affiliation with this developer.

Import from Excel to MySQL database using SQuirrel

I have an Excel spreadsheet with a few thousand entries in it. I want to import the table into a MySQL 4 database (that's what I'm given). I am using SQuirrel for GUI access to the database, which is being hosted remotely.
Is there a way to load the columns from the spreadsheet (which I can name according to the column names in the database table) to the database without copying the contents of a generated CSV file from that table? That is, can I run the LOAD command on a local file instructing it to load the contents into a remote database, and what are the possible performance implications of doing so?
Note, there is a auto-generated field in the table for assigning ids to new values, and I want to make sure that I don't override that id, since it is the primary key on the table (as well as other compound keys).
If you only have a few thousand entries in the spreadsheet then you shouldn't have performance problems (unless each row is very large of course).
You may have problems with some of the Excel data, e.g. currencies, best to try it and see what happens.
Re-reading your question, you will have to export the Excel into a text file which is stored locally. But there shouldn't be any problems loading a local file into a remote MySQL database. Not sure whether you can do this with Squirrel, you would need access to the MySQL command line to run the LOAD command.
The best way to do this would be to use Navicat if you have the budget to make a purchase?
I made this tool where you can paste in the contents of an Excel file and it generates the create table, and insert statements which you can then just run. (I'm assuming squirrel lets you run a SQL script?)
If you try it, let me know if it works for you.