I have a table that exists currently, and I want to add in a column from another table via a join. Is there a way to add it to this table and not have to create a new one? I know I could easily make another table with by joining the data in but I wasn't sure if there was a way to insert that kind of data to an existing one.
Related
I was trying to figure out an easy and fast way to create a table A from another table B which has more than 400 columns. Just a create or replace table statement as below would have worked.
create or replace table A
AS select * from B where 1=2
However, I need to create table A with an extra column as ID and also need to add clustering on this column ID. Altering the table later will also do but I understand that I cannot add clustering once the table is created. I do not want to write a DDL specifying all 400 columns. Can this be achieved in an easy and faster way?
I was also looking at options to create table dynamically by using INFORMATION_SCHEMA.COLUMNS information. However, I am not yet sure of that.
In SQL Server 2008, I need to create a child table from parent big table copying it's values in two columns and updates automatically. These values must be distinct and copy into corresponding two columns in new table. The whole idea would be making reference table with these distinct values and make relation with parent table. Thanks
Enkhzul,
You'll want to create a VIEW. A VIEW will simply run a SELECT query in the background against any tables you request in the query and display as instructed. Syntax will be:
USE [DATABASE]
GO
CREATE VIEW [VIEWNAME] AS
(
select statement here
)
After that you just need to do a SELECT query against the newly created VIEW.
I have two identical tables in the database (Same column name, same data type). Table A and Table B.
A is the master table. Now i want to update the table B with the changes done in the master table A automatically at any point of time. How would i do that without using DBMS_COMPARISON
I have two tables in my database, one is Transactions and the other is TransactionHistories. The latter is essentially an auditing table, whereby a trigger executes on insert, update and delete on Transactions to capture a screenshot of the data.
I am successfully retrieving all of the data stored in the Transactions table where the columns match, but the difficulty comes where I am trying to retrieve data from another table using a foreign key. For instance:
The transaction table has a field "TransactionType_TransactionTypeId", but in the audit table we wish to store its 'name' equivalent as "TransactionTypeName". This needs to be populated from the "TransactionTypes" table, which has the fields "TransactionTypeId" and "Name".
I am struggling to write a query to retrieve this as we wish. I am trying something similar to the following but having little success:
SELECT #TransactionTypeName=Name
FROM TransactionTypes
WHERE inserted.TransactionType_TransactionTypeId=TransactionTypes.TransactionTypeId;
I'm assuming that is a syntactic nightmare. If someone could point me in the right direction I would be extremely grateful!
well to get a name you should do the following
select #TransactionTypeName = TT.Name
from inserted as i
left outer join TransactionTypes as TT on TT.TransactionTypeId = i.TransactionType_TransactionTypeId
but you have to know that inserted table can have more than one row, and you are getting value for only one row.
in ms-access, how to write a query / DDL to change multiple column names with a single query.
You have to create a new table, copy data, drop old table
ALTER TABLE does not support multiple ...ALTER COLUMN clauses
You could ADD multiple columns on one go, populate then, then drop the old columns.
Multiple ADDs are supported.