Nothing from a table shows up in SQL - sql

I have several table created by recently i can get anything to come from one of them.
The table is called REP and i'm currently using Live SQL from Oracle as i'm quite new to SQL
The select command i'm trying to use.:
select * from REP
I go to my schema and the table is definitely there. No commands for this table work.:
If anyone could help i'd very much appreciate it. Don't be too hard on me i'm quite new to SQL.

Your table is empty. First insert the values into this table via
INSERT INTO REP VALUES(...)
and
then use your query Select * from rep
As in your image, the table is there thats the ddl view meaning table's structure not data i.e. you have only columns but no data.

Related

Adding Columns - SQL Server Tables

I have been asked to look into a manual process that one of my colleagues is completing every now and again.
He sometimes needs to add a new column onto a large table (200 million rows), it is taking him more than 1 hour to do this. Before you ask, yes, the columns are nullable but sometimes the new column will have 90% data in it.
Instead of adding a new column to the existing table, he...
Creates a new table
Select (*) from old table (inserts into new)
Adds the new column as part of his script
Then he deletes the old table and renames the new table back to the original, adds index and then compresses. He says it much quicker like that.
If this is the best way then I will try and write SSIS package to try and make the process more seamless
Any advice is welcome!
Thanks
creating a new table structure and moving all the data to that table and delete the prior table is a good way just for a few data,you can do it by wizard in SQL Server. but it is the worst way for solving this problem(millions of data).
for large amount of data (millions of records) you should use "Alter Table".
Alter Table MyTable
ADD NewColumn nvarchar(10) null
the new column will add to the table as the last column.
if you use this script it takes less that one second because all data will not moving,you just add a new column in to the table.
but if you use the wizard method as you mentioned with millions of data records it takes hours.
as Ali says
alter Table MyTable
ADD NewColumn nvarchar(10) null
but then to fill in 90% of data. As he has a table already with it in and the key he's joining on in the copy so this is all he needs:
UPDATE MyTable
SET [NewColumn] = b.[NewColumn]
FROM MyTable a INNER JOIN NewColumnTable b ON a.[KeyField]= b.[KeyField]
would be a lot quicker. You could do it in SSIS but if this happens a lot then not really worth it for a few lines of SQL.

Huge Data Base in oracle

I had about 20,000,000 records
in a table (random data), and then I added empty column to that table...
but when I update that table to fill that column, the process was broken down..
I tried to use the cursor and the index but no results..
do you have any fast solution or any alternative solution?
Thank you in advance :)
Maybe the fastest way would be to create new_table as select * from existing table, and then inside the select statment of CTAS, calculate the value of the new column. After that, you can rename old table to something like table_bckp, then rename new table to the original table name, and then apply constraints, indexes, and other scripts previously saved from old table definitions.

Oracle SQL merge tables without specifying columns

I have a table people with less than 100,000 records and I have taken a backup of this table using the following:
create table people_backup as select * from people
I add some new records to my people table over time, but eventually I want to merge the records from my backup table into people. Unfortunately I cannot simply DROP my table as my new records will be lost!
So I want to update the records in my people table using the records from people_backup, based on their primary key id and I have found 2 ways to do this:
MERGE the tables together
use some sort of fancy correlated update
Great! However, both of these methods use SET and make me specify what columns I want to update. Unfortunately I am lazy and the structure of people may change over time and while my CTAS statement doesn't need to be updated, my update/merge script will need changes, which feels like unnecessary work for me.
Is there a way merge entire rows without having to specify columns? I see here that not specifying columns during an INSERT will direct SQL to insert values by order, can the same methodology be applied here, is this safe?
NB: The structure of the table will not change between backups
Given that your table is small, you could simply
DELETE FROM table t
WHERE EXISTS( SELECT 1
FROM backup b
WHERE t.key = b.key );
INSERT INTO table
SELECT *
FROM backup;
That is slow and not particularly elegant (particularly if most of the data from the backup hasn't changed) but assuming the columns in the two tables match, it does allow you to not list out the columns. Personally, I'd much prefer writing out the column names (presumably those don't change all that often) so that I could do an update.

Query to Access Sharded Tables

I am querying a vendors database that has data that is sharded between multiple tables. The tables are named Events_1, Events_2, Events_3, Events_4 etc.
It appears that a new table is automatically created when the table hits 10,000 records. I am looking to write a query that would be able union the results from all the tables (without having to manually add the tables as they are created) as well as a query to only look at the 2 newest tables.
Any suggestions on the best way to go about this?
The database is Microsoft SQL Server 2008
You can do this with dynamic SQL such that you query sysobjects for table name Events_* and build a SELECT UNION from the results.
Better, though perhaps more complicated, would be a DDL trigger that would dynamically update you UNION VIEW to append the new table whenever a table Events_* was created.

Importing Data From One database to another

I wanted to know that, Suppose I have a table in one database with say 1000 records and I have similar table in another database with say 500 records.
Now my question is If I will try to import data from say DB1.Tbl1 to DB2.Tbl1, then what will happen? Is there any possibilities of duplicacy of the data?
I wanted the records of DB1.Tbl1 to copy into DB2.Tbl1 table. Please clear my confusion.
If you have same data in both tables you can first truncate 2nd table after that you can import data from 1st table by Insert Command or "import data" task
Try this
INSERT INTO DB1.dbo.Tbl1 SELECT * FROM DB2.dbo.Tbl2
This just moves the data. If you want to move the table definition, you have to do something else.
Note that, SQL Server Management Studio's "Import Data" task (right-click on the DB name, then tasks) will do most of this for you. Run it from the database you want to copy the data into.
If the tables don't exist it will create them for you, but you'll probably have to recreate any indexes. If the tables do exist, it will append the new data by default but you can adjust that (edit mappings) so it will delete all existing data.
Try this:
We can copy all columns from one table to another, existing table:
INSERT INTO table2
SELECT * FROM table1;
Or we can copy only the columns we want to into another, existing table:
INSERT INTO table2
(column_name(s))
SELECT column_name(s)
FROM table1;