I would like to create tables from existing tables without copying the data to the new tables in snowflake. Is this possible?
For example:
I have tables say "DB"."SCHEMA"."tb1" and "DB"."SCHEMA"."tb2".
I would like to create tables "DB"."SCHEMA"."tb3" and "DB"."SCHEMA"."tb4" from "DB"."SCHEMA"."tb1" and "DB"."SCHEMA"."tb2" without copying their data to "DB"."SCHEMA"."tb3" and "DB"."SCHEMA"."tb4".
Kindly help.
Thanks in advance.
The answer for above question is as below:
CREATE TABLE "DB"."SCHEMA"."tb3" LIKE "DB"."SCHEMA"."tb1"
CREATE TABLE "DB"."SCHEMA"."tb4" LIKE "DB"."SCHEMA"."tb2"
As rightly mentioned, "LIKE" operator when used with "create table" would create a table from parent without copying the data.
Here is the documentation for this command and example : https://docs.snowflake.com/en/sql-reference/sql/create-table.html
Related
I have a scenario wherein I have to convert transient snowflake table to permanent table and also have same grants and data share. Is there any way to do it?
Not directly, you can either follow a similar approach as explained here:
https://community.snowflake.com/s/article/Change-permanent-table-to-transient-table
or maybe something like this:
CREATE OR REPLACE TABLE permanent_table CLONE transient_table;
I'm not sure if something like this is possible, but I have a db file with multiple tables in it. In some of those tables there are guids that are used as references across the tables. Is there anyway I can basically do a search and replace of a value in all the tables? (One thing that make make this easier is that the column has the same name in every table). Thanks for any help.
You can open the .sqlite or .db file in any of the editors and do find and replace.
You can import the DB file in database and add property called ON UPDATE CASCADE and then perform update on the parent table.
You can write a script to update that particular element.
I am able to DROP and CREATE a temporary table but when I do a select, it doesn't recognize the object. I know it's there but how can I access it?
FYI, I have multiple databases in SQL Server (2008). I tried the below but it doesn't work.
SELECT *
FROM tempdb..#TBL_IMPORT
Usually to access tables I have to type this: dbname.dbo.tablename
Any clue? Thank you.
With the amount of information given, the answer is in the comments.
If you would like to query a temp table from a second session, you'll need to create the temp table as a global temp table.
select *
into ##MyGlobalTable
from SourceTable
If you're using SSMS you will want to use the same window you create the temp table in if not using a global temp table. If you're using a secondary application you'll want to validate you're using the same SPID.
Other approaches you may be interested in would include CTEs (common table expressions) and variable tables. Google will have a wide assortment of assistance, or you could update your question here.
In my database there are a table that is declared like MC something like this
CREATE TABLE [MC].[tb_products]()
What is it for? Or what is?
[MC] is a database schema. Advantages to using it are logical grouping and being able to control permissions.
See: What is purpose of database schema?
I have 2 database call CUSTOMER_NEW and CUSTOMER_OLD.
I want to use on table that is cust_info's design in CUSTOMER_NEW table without recreating all the field again.
And I want to do this by any method other than writing a code of using that table in that new database..
select * into customer_new.newtable from customer_old.originaltable