How to rename System Tables Name in SQL-Server_2014? - sql-server-2012

Can we change System Table names in sql server? If yes then guide me how to do that.
Also, how can I unmark system table? i.e. can I move a table from system tables to user-defined table?

In my experience, Table SQL Server is permanent and can not be replaced, but there are some software (third parties) that can rename tables in SQL Server or Solution #2 is export your database into the form of .sql and edit the table name from the .sql then import

Related

How to rename a database in azure databricks?

I am trying to rename a database in azure databricks but I am getting the following error:
no viable alternative at input 'ALTER DATABASE inventory
Below is code:
%sql
use inventory;
ALTER DATABASE inventory MODIFY NAME = new_inventory;
Please explain what is meant by this error "no viable alternative at input 'ALTER DATABASE inventory"
and how can I solve it
It's not possible to rename database on Databricks. If you go to the documentation, then you will see that you can only set DBPROPERTIES.
If you really need to rename database, then you have 2 choices:
if you have unmanaged tables (not created via saveAsTable, etc.), then you can produce SQL using SHOW CREATE TABLE, drop your database (be careful anyway), and recreate all tables from saved SQL
if you have managed tables, then the solution would be to create new database, and either use CLONE (only for Delta tables), or CREATE TABLE ... AS SELECT for other file types, and after that drop your database
Alex Ott's answer, to use Clone, is OK if you do not need to maintain the versioning history of your database when you rename it.
However if you wish to time travel on the database of Delta tables after the renaming, this solution works:
Create your new database, specifying its location
Move the file system from the old location to the new location
For each table on the old database, create a table on the new database, based on the location (my code relies on the standard file structure of {database name}/{table name} being observed). No need to specify schema as it's just taken from the files in place
Drop old database
You will then be left with a database with your new name, that has all of the data and all of the history of your old database, i.e. a renamed database of Delta tables.
Pyspark method (on databricks, with "spark" and "dbutils" already defined by default) :
def rename_db(original_db_name, original_db_location, new_db_name, new_db_location):
spark.sql(f"create database if not exists {new_db_name} location '{new_db_location}'")
dbutils.fs.mv(original_db_location,new_db_location,True)
for table in list(map(lambda x: x.tableName, spark.sql(f"SHOW TABLES FROM {original_db_name}").select("tableName").collect())):
spark.sql(f"create table {new_db_name}.{table} location '{new_db_location}/{table}'")
spark.sql(f"drop database {original_db_name} cascade")
return spark.sql(f"SHOW TABLES FROM {new_db_name}")

transfer single table data from one Database to other database with same table name?

How can i transfer single table data from one Database to other database with same table name?
I have a database with data and other one has no data.
They are not exactly the same as but one table is the same
Thanks
There are many ways to export a table. Some are,
Using SELECT INTO Query
Select * into Database1.Department from Database2.Department
Using SQL Server Export / Import wizard
a. From SQL Server Management Studio, right-click on the database name in the object explorer, then choose Tasks -> Export Data
b. Choose a Data Source and Destination
c. Select the source table and follow the steps and execute the package
For more info, check http://www.sqlshack.com/how-to-copy-tables-from-one-database-to-another-in-sql-server/
Edited Note:
The above methods are for Microsoft SQL Server.

Copy (Import) Data from Oracle Database To Another

I want to Copy a data from One oracle database to another.
I have checked Import/Export Utility but the problem is import utility doesn't support conflicts resolution techniques between rows.
For Example if there's a table in the source database have the same row key in the destination database. if i use 'Ignore' parameter with value = y, the destination table will have a duplicate rows.
I want to ask if there's another way to import data from oracle database to another with some mechanism of detecting the conflicts and resolve them?
You might want to consider using a database link from database A to database B. You can query the data from database B to insert into your database A tables. You are free to query whatever you want using SQL or PL/SQL.
More on database links:
http://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_5005.htm

How can i combine more then one database's data in one database with same schema

I have a 5 database with same schema, i want to copy all data in one database with same schema
or how can i copy data from *.mdf files in database.
i am using sql server 2005
Copy Database with T-SQL:
sqlauthority
http://blog.sqlauthority.com/2009/07/29/sql-server-2008-copy-database-with-data-generate-t-sql-for-inserting-data-from-one-table-to-another-table/
Copy Database with Wizard:
kodyaz
http://www.kodyaz.com/sql-server-tools/sql-server-copy-database-wizard.aspx
I'd suggest taking a look at Red Gate SQL Data Compare. That will enable you to merge the data between the two databases and directly control which one wins in any given situation.
As mentioned above you need to deal with the Primary Keys as well...
One way to deal with this to add a "Database ID" to all the tables in the single central version. The central PKs become the PK from the source table, plus the "Database ID". This way you have unique PKs in the central version AND you can tell which database the row came from. This is what sql-hub does - there is a free licence which will let you do this as a one-off task - or you could do the inserts for each database and table in SQL.

Oracle 10g- exporting and importing Table

I need a command for importing a table for the following scenario.
I have a table EMPLOYEE in server A. I am exporting the Table.
I have another table PDATA(having same structure of EMPLOYEE table) in server B.
I need to import the records from EMPLOYEE table(server A) into PDATA table(server B).
I am using Oracle 10g. Please advise.
There are a couple of options. I am going to assume that you don't have any binary data and that the tables aren't absurdly large. We also don't know what type of access you have to either server.
You could use a tool, such as TOAD, to either export to csv or create insert statements. Then execute those on the second server.
You could use PL/SQL and the UTL_FILE library to dump the contents of the table to a csv file. Then mount the csv file as an external table and select into your new table.
If you have the appropriate permissions and the machines can physically see each other you can setup a database link: http://docs.oracle.com/cd/B14117_01/server.101/b10759/statements_5005.htm Once the link is created, you can select from one table into the other.
If you are a DBA then you can use the Export utility, which will export the table into a binary format that can be imported elsewhere.