How to export all data from table to update MS SQL commands? - sql-server

I have a MSSQL database that has a 'settings' table with more than 500 rows. I want to generate a script of UPDATE commands including all the data. This will run against an existing database, and the data will replace what is currently in the table.
I have attempted to use the answer found here: How to export all data from table to an insertable sql format? but I get INSERT statements, which won't work.
I cannot drop and re-create the table, because it has foreign keys.
Disclaimer: I did not design this. I wouldn't put foreign keys on settings.

I use the Vroom SQL Script Generator for that. Its free and it does exactly what you are asking - generates insert/update scripts from a table. Just click on "Export Data", select the objects you want to export and then click the Generate button. If you need to really fine tune the way the script are generated then you can also use the built in automation scripting support - which is referenced at the bottom of the link.

Related

PowerDesigner Possibility to drop tables when "Apply Model Changes to Database"

when generating a database in PowerDesigner I have the option to drop all Tables/Tablespaces and so on before generating the Database: Option to Select
But this Option isnt there when applying changes to a database. I need this, because some local databases could already have some of the Changes I made to the model and I cant drop all tables because of the data.
I'm not sure I understand the question, when you are ready to drop some tables instead of modifying them, but you don't want to drop all tables.
It seems to me that you could use Database > Apply Model Changes to Database with the Connect to a Data Source to compare the model with an existing database, and just generate the necessary modification scripts.
Maybe you could use a saved Selection to generate an Alter Script for most tables, and another to generate a Drop+Create script for some "transient" tables.

Insert data into SQL tables manually using the related columns in Management Studio

I am trying to insert data into some related table in SQL Server 2008R2 and I am trying to figure out whether there is an easier way to insert data manually (visually) using the related columns and not the IDs. If you check the two snapshots of the tables and table WFUserGroup basically I am trying to see if I can have a bound query (like in MS ACCESS) where I can see the Name column instead of the ID and the name of the Group instead of the group_id
I know that with a TRANSACTION block and INSERT INTO statements I can create a new user in WFUser table and then relate it to a group in the WFUserGroup table, but I am telling myself there should be an easier way. Anyone knows a workaround?
Tables:
Using Edit Top 200 Rows Feature:
You could use a flat file with data in a .csv or excel and use the Import feature in SQL server.
how to navigate, right click on the database and tasks--> Import then the wizard to select the necessary file and tables.
I do see that there are primary key and foreign keys so you have to make sure that its considered in your files you are going to import.

preserve the data while dropping a hive internal table

I have loaded a huge table from SQL Server onto Hive. The mistake I made is I created the table as a Internal table in HIVE. Can anyone suggest any hack so that I can alter the table structure , without dropping the data.
The data is huge and I cant afford to export the data out of source again.
The problem right now, is that since the column orders don't match the SQL server table, a lot of columns display NULL.
Any help will be highly appreciated.
I do not see any problem to use an Alter Table on a internal table. (https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-AlterTable/Partition/Column)
Another - but not recommended - option would be to open your hive metastore(HCatalog) and apply the changes there. Hive reads out the schema information from a relational database (configured during the Hadoop setup, default is MySQL). In this MySQL you can try to change some settings. However, this is not recommended as with a mistake, you can screw your whole Hive databases.
The safest way is creating a new table and using the existing as a source
create table new_table
as
select
[...]
from existing_table

Importing data into Oracle via Web Enterprise Manager with unique constraints

I am not at all familiar with Oracle so bear with me!
I am using version Oracle 10G with the web front end called Enterprise Manager. I have been given some CSV files to import however when I use the Load Data from User Files option I think I can set everything up but when the job runs it complains that there are unique constraints, I guess because there is duplicate data trying to be inserted.
How can I get the insert to create a new primary key similar to a MSSQL auto inc number?
Oracle does not have an analog to the MSSQL auto incrementing field. The feature has to be simulated via triggers and Oracle sequences. Some options here are to:
create a trigger to populate the columns you want auto incremented from a sequence
delete the offending duplicate keys in the table
change the values in your CSV file.
You might look at this related SO question.
There is no autoinc type in Oracle. You have to use a sequence.
By using a before insert trigger, you could get something similar to what you get by using an autoinc in SQL Server.
You can see here how to do it.

Using sql importer, how can I import schema details like PK/FK?

I did a sql import (sql08) and it didn't import PK/FK type information.
It only transfered data and created the tables.
How can I make it do this?
SCript the tables including scripting indexes, constraints, foreign keys etc.
Run the script then use the wizard to transfer the data into the new empty table using append rather thant create.
You could also using the wizard click on Edit mappings (onthe Select Source Tables and Views page) and then edit SQl and add the code for those things yourself to the table definition script.

Resources