Quantcast
Channel: Forum SQL Server Database Engine
Viewing all 15889 articles
Browse latest View live

select * into a specific file group

$
0
0

Hi Experts

looking for your advise on the following scenario

I have a database with one file in the primary file group (size 25 G), every 2 hours SQL Server agent job is fetching data into a temp table (#table) from a linked server, doing some updation and finally dropping the existing creating a new permanent table (tablename remains same, table size is about 500MB) in the database

drop table mypermtable
select * into mypermtable
from #myvaribale table

I want to isolate this object from others in a separate filegroup and looking for some solution to do it without changing any database level configuration like

ALTER DATABASE mydb
MODIFY FILEGROUP mynewgroup DEFAULT

secondly please advise, if frequent (every 2 hours) dropping table and recreating a table can make fragmentation in the datafile.

Best Regards


RollBack Process

$
0
0

Hello All,

There is  a process in one of our PROD server taking indefinite time to rollback, showing completion status 0% this process has been killed two days back, please find the below details of the process

-->dbcc inputbuffer(spid)

DECLARE

@shellINTEXECSP_OAcreate'{72C24DD5-D70A-438B-8A42-98424B88AFB8}',@shellOUTPUTEXECSP_OAMETHOD@shell,'run',null,'secedit.exe /configure /db secedit.sdb /cfg c:\windows\system32\PerfStringsa.ini /areas filestore','0','true';

 -->kill spid with statusonly

SPID: transaction rollback in progress. Estimated rollback completion: 0%. Estimated time remaining: 0 seconds.

could someone help me in this to get rid of above process and explain me what is the propose above process as I was not aware of above code .

with Regards,

ram

 



Question on AlwaysON backups in SQL2014

$
0
0

Hello!

According to this article:

http://blogs.msdn.com/b/sqlgardner/archive/2012/08/28/sql-2012-alwayson-and-backups-part-3-restore.aspx

"The second consideration has to do with the new ability to have a variable backup location.  If you are using thesys.fn_hadr_backup_is_preferred_replica function to determine the proper place for backups described in myprevious post, then you may have a full backup on Server1, some tran log backups on Server2, etc.  Where this can be a bit of a bummer is when you use any of the GUI tools in Management Studio to do restores. They use the backup history tables in MSDB in order to determine all the backupsets for a database.  This data is not shared or duplicated across instances. You will only see backups that were taken on that particular instance."

Consider the situation:

There're two servers that are part of the AlwaysOn group- SQL1 and SQL2.

I take backup of the db Resources on SQL2 on 17/02/2015 at 2:12PM (while SQL2 is secondary) and then take backup of the db Resources 17/02/2015 at 2:20 PM (while SQL1 is secondary, after the switchover). Here are the backup files:

Now if I were to restore the database from either SQL1 or SQL2 I would see the most recent backup available for the restoring - the .bak file created on 17/02/2015 at 2:20 PM:

Q: How can I see the backup created on SQL1 when working on SQL2 if "They use the backup history tables in MSDB in order to determine all the backupsets for a database.  This data is not shared or duplicated across instances. You will only see backups that were taken on that particular instance." ?

Is this due to any changes to SQL Server 2014 (the aforementioned article is on SQL Server 2012)?

Thank you in advance,

Michael


Scheduled Jobs and Server Maintenance

$
0
0

Hi All,

Running SQL 2012.  We have a series of scheduled jobs that run once per day, with no retry interval set.  I was informed by IT today that they need to perform unscheduled maintenance on the server this evening - which may or may not be completed by the time our jobs are set to run.  My question is: if a job is set to run at (say) 10pm, and the server is off - when it is restarted, does it try and execute this missed job?  Or does it just do nothing and next execute according to it's regular schedule (so, at 10pm the following night?)

Thanks.

How to view Windows event logs in SQL Error log viewer

$
0
0

Hi,

 I know that I used to see Windows events (App/Security/System) logs under SQL Server error log viewer along with SQL Agent logs & Database mail logs. But recently I observed that I don't see Windows logs anymore.

 Do you know how to get them back to view Windows logs under SQL log viewer?

 


If you feel that I have answered your question then please "Mark as Answer".

distributed query for license key

$
0
0

Hello,

I have a distributed query that I'm hoping is retrieving the license key information below:

USE master
GO

create table #version
(
	version_desc varchar(2000)
)

insert #version
select @@version

if exists
(
	select 1
	from #version
	where version_desc like '%2005%'
)
Begin
	DECLARE @Registry_Value_2005 VARCHAR(1000)
	EXEC xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL.1\Setup','ProductCode',@Registry_Value_2005 OUTPUT --2005
	SELECT @@version as 'version',@Registry_Value_2005 as 'license_key'
End
else if exists
(
	select 1
	from #version
	where version_desc like '%express%'
)
Begin
	DECLARE @Registry_Value_2008_express VARCHAR(1000)
	EXEC xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\Setup','ProductCode',@Registry_Value_2008_express OUTPUT -- 2008 express
	SELECT @@version as 'version',@Registry_Value_2008_express as 'license_key'
End
else if exists
(
	select 1
	from #version
	where version_desc like '%R2%'
)
Begin
	DECLARE @Registry_Value_2008_R2 VARCHAR(1000)
	EXEC xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\Setup','ProductCode',@Registry_Value_2008_R2 OUTPUT -- 2008 R2
	SELECT @@version as 'version',@Registry_Value_2008_R2 as 'license_key'
End
else if exists
(
	select 1
	from #version
	where version_desc like '%2008%'
)
Begin
	DECLARE @Registry_Value_2008 VARCHAR(1000)
	EXEC xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL10.MSSQLSERVER\Setup','ProductCode',@Registry_Value_2008 OUTPUT -- 2008
	SELECT @@version as 'version',@Registry_Value_2008 as 'license_key'
End
else if exists
(
	select 1
	from #version
	where version_desc like '%2012%'
)
Begin
	DECLARE @Registry_Value_2012 VARCHAR(1000)
	EXEC xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL11.MSSQLSERVER\Setup','ProductCode',@Registry_Value_2012 OUTPUT -- 2012
	SELECT @@version as 'version',@Registry_Value_2012 as 'license_key'
End
else
Begin
	select 'version not recognized'
End

drop table #version



I'm noticing the 'key' is coming back the same across our 2012 instances and I'm pretty sure this isn't right. Am I retrieving the right value from the registry? I want to get the actual key that is installed when SQL is installed. Please help also feel free to borrow this code if you like.

Thanks!

phil

Install second SQL instance onto existing cluster role

$
0
0

Hi,

We have a 3 node cluster running Windows Server 2012 R2 with 5 SQL clustered roles running SQL 2012 spread across them. For certain reasons we have a requirement to install a second SQL named instance onto one of the existing SQL roles. All of our SQL instances are currently running on different ports with no issues.

When we run the wizard to install the additional instance we specify the new instance name along with the existing network name to install to. However, we receive this error message:

"The SQL Server failover cluster instance name <existing role name> already exists as a clustered resource. Specify a different failover cluster instance name."

I am wondering if it is by design that it doesn't allow you to do this or a limitation of the GUI install? Is running multiple SQL named instances on a single cluster resource group/role supported?

Cheers
Brady


First Row Record is not inserted from CSV file while bulk insert in sql server

$
0
0

Hi Everyone,

I have a csv file that needs to be inserted in sql server. The csv file will be format will be like below.

1,Mr,"x,y",4

2,Mr,"a,b",5

3,Ms,"v,b",6

While Bulk insert it coniders the 2nd column as two values (comma separte) and makes two entries .So i used filelterminator.xml.  

Now, the fields are entered into the column correctly. But now the problem is, the first row of the csv file is not reading in sql server. when i removed the  terminator,  i can get the all records. But i must use the above code terminator. If am using means, am not getting the first row record.

Please suggests me some solution.

Thanks,

Selvam





Be our next Spring SS DBE Guru!

$
0
0



In the northern hemisphere at least, Spring is here! (apparently)

And at TechNet Wiki, we're hoping you're all hatching new ideas for this month's TechNet Guru competition!

We're looking for more shoots and leaves of wisdom to sprout forth from the great tree of MSDN/TechNet life.

We're also hoping some of our old Guru winners will be coming back out of hibernation and flexing their grey matter!

So, pick up your pen and MARCH into TechNet History! This could truly be the start of something BEAUTIFUL!

What delightful new arrival will YOU be bringing into this world?

All you have to do is add an article to TechNet Wiki from your own specialist field. Something that fits into one of the categories listed on the submissions page. Copy in your own blog posts, a forum solution, a white paper, or just something you had to solve for your own day's work today.

Drop us some nifty knowledge, or superb snippets, and become MICROSOFT TECHNOLOGY GURU OF THE MONTH!

This is an official Microsoft TechNet recognition, where people such as yourselves can truly get noticed!

HOW TO WIN

1) Please copy over your Microsoft technical solutions and revelations toTechNet Wiki.

2) Add a link to it on THIS WIKI COMPETITION PAGE (so we know you've contributed)

3) Every month, we will highlight your contributions, and select a "Guru of the Month" in each technology.

If you win, we will sing your praises in blogs and forums, similar to the weekly contributor awards. Once "on our radar" and making your mark, you will probably be interviewed for your greatness, and maybe eventually even invited into other inner TechNet/MSDN circles!

Winning this award in your favoured technology will help us learn the active members in each community.

Feel free to ask any questions below.

More about TechNet Guru Awards

Thanks in advance!
Pete Laker



#PEJL
Got any nice code? If you invest time in coding an elegant, novel or impressive answer on MSDN forums, why not copy it over toTechNet Wiki, for future generations to benefit from! You'll never get archived again, and you could win weekly awards!

Have you got what it takes o become this month's TechNet Technical Guru? Join a long list of well known community big hitters, show your knowledge and prowess in your favoured technologies!

Get last record in a SQL database

$
0
0
Don't know if this is the right SQL section, but... using VBE, how do you SQL for the last record in the database?

Thanks.

Dynamic column support in Bulk Load

$
0
0

Hi,

Is there any solution for the following scenario in bulk insert. 

"The csv file which is going to get processed for a particular table will change its column order periodically , and sometimes some columns will be deleted and sometimes some new columns will be added . I need to map corresponding column value from csv to table when the  order changes or values deleted or new values added"

Hope you will get ?

~Selva

SQL server 2014 DB creation issue

$
0
0

Hi,

I have created VM (windows server 2012) which is installed with SQL server 2014 standard version from gallery. when I tried to create a DB in SQL server it is taking too much time (more than half an hour it will be in the executing state) to create. so I restarted SQL server and finally deleted the VM and created new one but no luck, the problem remains the same.

please help me to resolve this.

thanks in advance!!

regards,
Naveen

Email when High SQL Disk IO

$
0
0

Hi,

Is there anyway I can setup an alert/email on my SQL server to fire email as it detect high DiskIO. we are having disk latency more often now and I can't narrow it down, as soon as tech team inform me and I jump on to server, everything comes back to normal.

Thanks

I am using SQL Server 2008 R2 Standard Edition with SP2 on widows 2008 R2 Standard

BulkCopy Issues with SQL

$
0
0

Hello everyone, my question is in regards to a bulkcopy insertion in sql. 

My Table is very simple: 

ID (uniqueidentifier, set as primary key) 

Data (nvarchar(MAX)) 

INDEX: On ID (clustered, unique, hosted on primary key) 

I'm running a small script in C# that uses a bulkcopy to take a massive amount of excel files (approximately 30,000 rows in each file) and copies them into the table. 

At first I was copying files insanely fast, and was very happy with the results. 

Here's a snippet of the current code for reference 

 DataTable ColumnData = new DataTable();
                    ColumnData.Columns.Add("ID", typeof(Guid));
                    ColumnData.Columns.Add("Data", typeof(string));

//Add Data

 try
                    {

                        using (SqlBulkCopy bulkCopy = new SqlBulkCopy("CONNECTIONSTRING", SqlBulkCopyOptions.TableLock | SqlBulkCopyOptions.KeepIdentity | SqlBulkCopyOptions.KeepNulls))
                        {
                            bulkCopy.BatchSize = 10000;
                            bulkCopy.DestinationTableName = "dbo.TestData";
                            try
                            {
                                CentralDatabase.Open();
                                bulkCopy.BulkCopyTimeout = 0;
                                bulkCopy.WriteToServer(ColumnData);
                                CentralDatabase.Close();
                                Console.WriteLine("Data Inserted.");
                                ColumnData.Rows.Clear();
                            }
                            catch (Exception ex) { Console.WriteLine(ex.Message); CentralDatabase.Close();  };

                        }
                    }
                    catch (Exception ex) { CentralDatabase.Close(); };

After about 15,000,000 rows of data however everything slowed down to a crawl. 

I'm certain it's coming from SQL, but I'm not sure where I can go from here.

Is it my index? Should I change it to a nonclustered type? 

SQLSERVER 2012 LOG BACKUP

$
0
0

Hi Friends,

I want to inquire, as our sqlserver 2012 in full  recovery mode , when ever we are taking backup using netbackup , the logfile size did not shrink or reduce. My question is what is default behavior of sqlserver 2012 after taking logfile backup the logfile size should reduce or not. As the logfile size keep increase which creating problem.

thank you.

regards,

 


asad


Capture @@ROWCOUNT for all QUERIES using SQL AUDIT

$
0
0

I have a requirement where the customer wants to audit all SELECT queries made to a specific table  and also capture"No of rows returned" for these queries made to the table. I was able to capture various SELECT queries happening in the database /Table using SQL AUDIT, Wondering if anybody can suggest how to capture no of rows affected along with it, Since we have numerous stored procedures in the system we wont be able to modify existing stored procedures.


 

Auto Execute of SQL Job

$
0
0

I have SQL job which is scheduled to run every 5 minutes. When it executes it runs for a minute. I want to change this job to run more frequently (not to wait for 5 minutes) as soon as it successful execution, it has to wait for 10 seconds and start executing again. How shall I accomplish this? Thanks for your help..

Linked Server [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

$
0
0

Hi  I have SQL2012 installed on my local machine and have also installed MySQL 5.6.23 installed with a test database.

I also have my SQL connector installed and MYSQL ODBC Driver 3.51.   

Which happily connects to the Mysqldb.

The Datasource Name : mySQL conn

TCP/IP Server : localhost and Port :3306

User root

with pwd

On the SQL side I have used the following

EXEC master.dbo.sp_addlinkedserver
  @server = N'MYSQLSRV',
  @srvproduct=N'mySQL conn',
  @provider=N'MSDASQL',
  @datasrc=N'mySQL conn'

However when I try to selet using open query

SELECT * FROM OPENQUERY ( [MYSQLSRV], 'SELECT * FROM students' )

it comes back with

OLE DB provider "MSDASQL" for linked server "MYSQLSRV" returned message "[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified".
Msg 7303, Level 16, State 1, Line 1
Cannot initialize the data source object of OLE DB provider "MSDASQL" for linked server "MYSQLSRV".

I cant understand what I have done wrong .   Any help in this would be great as Ive hit a bit of a brick wall

Filestream - SqlFileStream constructor throws "Access is denied"

$
0
0

SQL Server 2012, IIS 7.0, .Net 4.5

Everything is fine when I stream a document on my dev machine (IISExpress), but on the staging server I get

System.ComponentModel.Win32Exception (0x80004005): Access is denied
   at System.Data.SqlTypes.SqlFileStream.OpenSqlFileStream(Stringpath, Byte[]transactionContext, FileAccessaccess, FileOptionsoptions, Int64allocationSize)
   at System.Data.SqlTypes.SqlFileStream..ctor(Stringpath, Byte[]transactionContext, FileAccessaccess, FileOptionsoptions, Int64allocationSize)

Kerberos with delegation is set up between the staging IIS and SQL Server, database queries work fine on the staging server and integrated security works - I can see in sql profiler that I am getting to the sql server with my Active Directory credentials and I am set up as sysadmin for now. So I am wondering, what could possibly go wrong with the filestream access:

- Sql server and my account are set up fine, otherwise it would not work on my dev machine

- The staging server uses a valid conection to the sql server, otherwise I would not see my NT user name in profiler

- It can not be a two hop problem, since the same error pops up when I request the page from IE running on the staging server

- My C# code is very likely not the problem source, since I tried an additional coding example from MSDN and I am getting the same security exception with that (but the MSDN code also works on my dev machine)

I read a number of similar questions in the forums but typically an sql server login was the problem (which is not used in my scenario), and many such questions stayed unanswered. I also read that NTFS permissioning could be the problem but I don't think so since only the sql server service account needs access to the files (which it has, otherwise I would never be able to upload and download files).

I/O Frozen message in the Error logs

$
0
0

I see very often this message, do I need to take care any precautions, is it going to effect in long run?

I/O is frozen on database master. No user action is required. However, if I/O is not resumed promptly, you could cancel the backup.

Viewing all 15889 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>