What is a clean way to copy a SQL table with more than 1000 rows? [closed] - sql

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
I know the question "How to copy table with more than 1000 rows" is already asked. I have read a lot about it and the different solutions like:
use export to excel and than import in new table
use UNION ALL (but not recommend)
use bulkreader
export to file and import
etc.
All the solutions sounding like a workaround. I am asking myself, is there no "official", clean way to do it?
Thank you.
Edit:
SELECT INTO was tried
INSERT INTO was tried
Using sql MS MGM studio
using HeidiSQL
Working on a MS SQL Server 13.0.4001.0

The cleanest and fastest solution with T-SQL would be into:
select *
into [destination table]
from [source table]
This will copy your data into a [destination table]. Be mindful of the remarks and limitations in the documentation regarding this keyword.

Related

How can I get the table name in a SQL Server trigger function? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I tried to get the table name in a SQL Server trigger function but I can't.
Please help me.
Try this query for get the table name using trigger function:
#tablename = OBJECT_NAME(parent_object_id)
FROM sys.objects
WHERE sys.objects.name = OBJECT_NAME(##PROCID)**

How to use sp_depends for other database [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Using SQL Server 2010
For updating the tables i am using following line
update database1_ab..table1
For sp_depends i am getting error as "Incorrect syntax near '.'"
sp_depends database1_ab..table1
How to use sp_depends for referring other database tables in current database
regardless, you need to put it in single quotes... ie
sp_depends 'database1_ab..table1'
or
sp_depends '[database1_ab]..[table1]'
You can call all the sp_ -procedures also in different database like this:
database1_ab..sp_depends table1

SQL Fiddle - date format not recognized [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
So as someone advised me yesterday I'm using SQL Fiddle since it's an easy way to test database queries and SQL programming in general but I'm getting this error:
Schema Creation Failed: ORA-01821: date format not recognized
This happens in the insert line. This usually works in Oracle and I selected in the combobox on top of the page Oracle 11g. So what's the problem?
create table Reparacoes(
numero_r int,
matricula char(8),
dataEntrada date,
constraint pk_carro primary key(numero_R),
constraint check_matricula check (regexp_like(matricula,'[[:number:]]{2}-[[:alpha:]]{2}-[[:number:]]{2}')));
insert into Reparacoes values (1,'S2-SS-12',to_date('yyyy-mm-dd','2013-11-10'));
By my own stupidity I was using the to_date wrongly. It's supposed to be like this:
to_date('2013-11-10','yyyy-mm-dd'));
and not like this:
to_date('yyyy-mm-dd','2013-11-10'));

Error message from simple SELECT statement with practice database [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I use the AdventureWorks practice database attached to SQL Server 2012.
A simple statement like:
SELECT * FROM HumanResources.Shift;
gives me this error:
Msg 208, Level 16, State 1, Line 1
Invalid object name 'AdventureWorks2012'.
I also tried:
USE master
GO
SELECT * FROM HumanResources.Shift;
Received same error message. Any idea to why this is happening?
Is AdventureWorks2012 the name of a database or a table?
USE <database name>
means use the specified database to run the query against.
SELECT * FROM <table name>
means select all the rows from the specified table.
--Edit because of change in question--
You don't want to use Master, you want to use the name of your DB. Next, using the object explorer, I would make sure the table actually exists in the Database you created.

Recover Updated Data - SQL Server 2005 [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I have an issue that, while using sql server 2005 i have executed update query without where clause (by mistake) and all the original values of the column get lost.
How can I get old values??
Any suggestion/tips/solution is welcome and will be highly appreciated.
Hi AngelIII,
SQL server keeps log for every transation.So you can recover your modified data from the log as well without backup.
Select [PAGE ID],[Slot ID],[AllocUnitId],[Transaction ID] ,[RowLog Contents 0]
, [RowLog Contents 1],[RowLog Contents 3],[RowLog Contents 4] ,[Log Record]
FROM sys.fn_dblog(NULL, NULL)
WHERE AllocUnitId IN
(Select [Allocation_unit_id] from sys.allocation_units allocunits
INNER JOIN sys.partitions partitions ON (allocunits.type IN (1, 3)
AND partitions.hobt_id = allocunits.container_id)
OR (allocunits.type = 2 AND partitions.partition_id = allocunits.container_id)
Where object_id=object_ID('' + 'dbo.student' + ''))
AND Operation in ('LOP_MODIFY_ROW','LOP_MODIFY_COLUMNS')
And [Context] IN ('LCX_HEAP','LCX_CLUSTERED')
Here is the artcile, that explains step by step, how to do it. http://raresql.com/2012/02/01/how-to-recover-modified-records-from-sql-server-part-1/
Restore a backup taken before the update
Restore transaction logs to a point in time before the update
Restore a copy of the table you made before the update
Rollback the transaction that contains the update
It's difficult to offer a specific solution not knowing what precautions you have taken. These may not solve your problem, but may prevent this from happening in the future.
DON'T MESS AROUND WITH SQL THAT ALTERS PRODUCTION DATA UNTIL YOU HAVE ANSWERED THIS QUESTION.