Kusto explorer does allow scripting out functions and tables using the UI option "make command script". Is there any way we can use some sort of Kusto command to generate exactly the same output? Basically looking for command counterpart for clicking "make command script".
Continuing Yoni's answer, this should give you an executable command
.show table MyTable cslschema | project strcat(".create table ",TableName," (", Schema , ")")
project lets you select what to output (same as SELECT in sql)
strcat lets you concat string
.show table T cslschema (doc) should bring you close to that
Related
I would like to load text from a field in a SQLite table and run it as a SQLite query. All done in a SQLite query. No external string operations, nor command line operations are possible. Pure SQLite only.
Let's say that I would create a table command_table with the rows:
COMMAND_NAME: COMMAND:
command1 SELECT * FROM table1
command2 SELECT * FROM table1 WHERE table1.row1 = '1'
The desired SQLite command would be able to load the COMMAND and interpret it.
The commands would be as complex as it gets, so using some generic comparisons like WHERE table1.row1 = command_table.command1" is not an option.
SQLite is designed as an embedded database, i.e., to be used together with a 'real' programming language. Therefore, it does not have any mechanism to execute dynamic SQL statements from within SQL itself.
The only thing I don't have an automated tool for when working with Oracle is a program that can create INSERT INTO scripts.
I don't desperately need it so I'm not going to spend money on it. I'm just wondering if there is anything out there that can be used to generate INSERT INTO scripts given an existing database without spending lots of money.
I've searched through Oracle with no luck in finding such a feature.
It exists in PL/SQL Developer, but errors for BLOB fields.
Oracle's free SQL Developer will do this:
http://www.oracle.com/technetwork/developer-tools/sql-developer/overview/index.html
You just find your table, right-click on it and choose Export Data->Insert
This will give you a file with your insert statements. You can also export the data in SQL Loader format as well.
You can do that in PL/SQL Developer v10.
1. Click on Table that you want to generate script for.
2. Click Export data.
3. Check if table is selected that you want to export data for.
4. Click on SQL inserts tab.
5. Add where clause if you don't need the whole table.
6. Select file where you will find your SQL script.
7. Click export.
Use a SQL function (I'm the author):
https://github.com/teopost/oracle-scripts/blob/master/fn_gen_inserts.sql
Usage:
select fn_gen_inserts('select * from tablename', 'p_new_owner_name', 'p_new_table_name')
from dual;
where:
p_sql – dynamic query which will be used to export metadata rows
p_new_owner_name – owner name which will be used for generated INSERT
p_new_table_name – table name which will be used for generated INSERT
p_sql in this sample is 'select * from tablename'
You can find original source code here:
http://dbaora.com/oracle-generate-rows-as-insert-statements-from-table-view-using-plsql/
Ashish Kumar's script generates individually usable insert statements instead of a SQL block, but supports fewer datatypes.
I have been searching for a solution for this and found it today. Here is how you can do it.
Open Oracle SQL Developer Query Builder
Run the query
Right click on result set and export
http://i.stack.imgur.com/lJp9P.png
You might execute something like this in the database:
select "insert into targettable(field1, field2, ...) values(" || field1 || ", " || field2 || ... || ");"
from targettable;
Something more sophisticated is here.
If you have an empty table the Export method won't work. As a workaround. I used the Table View of Oracle SQL Developer. and clicked on Columns. Sorted by Nullable so NO was on top. And then selected these non nullable values using shift + select for the range.
This allowed me to do one base insert. So that Export could prepare a proper all columns insert.
If you have to load a lot of data into tables on a regular basis, check out SQL Loader or external tables. Should be much faster than individual Inserts.
You can also use MyGeneration (free tool) to write your own sql generated scripts. There is a "insert into" script for SQL Server included in MyGeneration, which can be easily changed to run under Oracle.
How do you attach two sqlite db inside a shell script and script operations with their aliases?
for example: from the sqlite3 shell I can attach two different dbs, lets say db1 and db2, and then use:
insert into db2.table1(column1) select column1 from db1.table1;
to copy one column from a specific table on db1 to a specific table on db2.
but, how do I do that same inside a shell script?
To give multiple lines to the input of another program, you could redirect from a temporary file, or from a here document:
sqlite3 "" <<EndOfSqlite3Commands
ATTACH 'database1.db' AS db1;
ATTACH 'database2.db' AS db2;
INSERT INTO db2.table1(column1) SELECT column1 FROM db1.table1;
EndOfSqlite3Commands
How does one prepare a statement from the SQLite CLI? I have found the page Compiling An SQL Statement but it is geared more towards the ODBC interface, not the CLI interpreter. I'm hopinpg for something akin to the following:
sqlite> pq = prepare(SELECT * FROM Users WHERE username=?)
sqlite> run(pq, 'jeffatwood')
0 | jeffatwood | hunter2 | admin
sqlite>
Does the SQLite CLI have any such functionality? Note that I am not referring to the Bash CLI but rather SQLite's CLI interpreter or the excellent LiteCLI alternative.
Perhaps SQL Parameters using named parameters would do the trick
sqlite> .param set :user 'jeffatwood'
sqlite> select * from Users where username = :user
should return the desired row.
CLI was not designed for such. For this you must use an SQLite API on an available programming language.
You may also write a batch/shell file to handle CLI call.
E.g., in Windows a file named User.bat like following:
#SQLITE3.EXE some.db "SELECT * FROM Users WHERE username='%~1'"
May be called like this:
User "jeffatwood"
will perform desired result.
EDIT:
About prepared/compiled statements: with those you can bind parameters, fetch queries row by row and repeat same command in a faster manner.
sqlite3 CLI tool wouldn't take any advantage on those:
all parameters must be typed in SQL statement, making binding useless;
all query rows are returned at once, no need to fetch row by row;
repeated commands must be retyped - small speed improvement would result in using precompiled statements.
Is there a way to output the pl/sql script to datagrid directly? I have a pl/sql script which outputs to console using dbms_output.putline(). I am trying to execute this with TOAD and would like to know if there is any option available to re-route the output to daragrid besides printing it to the console.
Thanks,
Jasu
Probably, no. But you can use one of the following solution :
Use a temporary table and then select on the table.
Use a collection and then select on the collection.