Questions tagged [tsql]

Transact-SQL is the Microsoft extension of ANSI standard SQL.

Filter by
Sorted by
Tagged with
0 votes
3 answers
140 views

How do I get something like the INFORMATION_SCHEMA.COLUMNS metadata view of the INFORMATION_SCHEMA.COLUMNS view itself?

All columns of the INFORMATION_SCHEMA.COLUMNS view are listed at Learn -> SQL -> SQL Server -> COLUMNS (Transact-SQL):: COLUMN_NAME is of data type nvarchar(128): But there is no more ...
questionto42's user avatar
-2 votes
0 answers
42 views

TSQL query to get metadata statistics like granularity, number of rows, indexes, keys, sort of a broadened INFORMATION_SCHEMA.STATISTICS for TSQL [migrated]

The MySQL INFORMATION_SCHEMA.STATISTICS table has these columns: TABLE_CATALOG The name of the catalog to which the table containing the index belongs. This value is always def. TABLE_SCHEMA The name ...
questionto42's user avatar
0 votes
1 answer
260 views

Alter Database recovery model & Shrink log, DB dynamically

I normally do on daily basis these operations in GUI Alter database to simple recovery model shrink log file shrink database file Alter database to full recovery model I can understand script but ...
Shadow777's user avatar
0 votes
1 answer
153 views

Detect when scaling Azure SQL database via async TSQL command has failed

I have a scheduled task which runs each night to copy an existing production Azure SQL db to a dev environment. Once copied, I scale the database down (actually I put it into an elastic pool to share ...
theyetiman's user avatar
0 votes
0 answers
896 views

php 7 on Fedora 27: Uncaught Error: Call to undefined function sqlsrv_connect()

I have installed sqlsrv & pdo_sqlsrv per https://github.com/Microsoft/msphpsql/tree/PHP-7.0-Linux I created a test program that works perfectly from the command line but not when viewed in a web ...
faultintolerant's user avatar
1 vote
1 answer
476 views

How to take the column name dynamically with dates

I have column name with dates which comes from a table and changes from current month to last 41 month. and i have to write the column name again and again to reach the desired output. Is there any ...
user506566's user avatar
1 vote
1 answer
63 views

Why do I get different memory numbers using TSQL versus the GUI?

I'm preparing to bump up our max server memory value after a RAM upgrade on our server. I'm testing the commands out on a test SQL Server and I'm not sure why I'm seeing different results with T-SQL ...
cspell's user avatar
  • 205
0 votes
1 answer
531 views

Interpreting a Deadlock Log / XDL file

I've generated the following XML + XDL: <deadlock> <victim-list> <victimProcess id="processc1eaf13468" /> </victim-list> <process-list> <process id="...
SB2055's user avatar
  • 33
0 votes
1 answer
26 views

Convert into multiple data ranges

I have employee data link below This is one example in the file a have multiple lines. Initial input can have more than 2 lines for each employee but convert logic will be the same. Thank you for ...
user3030648's user avatar
0 votes
1 answer
320 views

Is it possible to connect to a PostgreSQL server using FreeTDS driver and tsql?

Can I make a connection to a PostgreSQL server using FreeTDS, more specifically tsql command? I've been trying for a few days now, using many different configurations. Even though I am able to ...
brunodea's user avatar
0 votes
1 answer
8k views

Bring back to restoring state an online database

I configured logshipping for a database. I did some tests and tried a controlled failover. During log shipping secondary db is in restoring state. To have a controlled failover i stopped the primary ...
giammin's user avatar
  • 107
0 votes
1 answer
1k views

T-SQL Code to backup database with multiple files failed

I'm trying to write an automated script that will allow me to backup the database to a NAS with multiple files. I just started to use T-SQL. My objective is to automatically calculate the size of the ...
Blake Zero's user avatar
0 votes
1 answer
4k views

Deal with dashes and spaces in T-SQL String functions

I am searching for the occurrence of a string in a field on a table. The search statement is done through dynamic sql with my statement template looking like this. SET @sSQL = 'UPDATE #...
Black Dynamite's user avatar
1 vote
1 answer
538 views

MSSQL: Roll back DB from backed up .MDF/.LDF

I've mistakenly deleted a table in Microsoft Server Management Studio, and the restore function was not properly configured. I have older .mdf and .ldf files of the particular db with the deleted ...
zillaofthegods's user avatar
3 votes
1 answer
9k views

How to rebuild MS Agent Jobs from MSDB table?

This morning our DB server died. They restored backups to another server but these didn't include the many MS Agent jobs. Anyway I have managed to get a backup of the old MSDB table where all the ...
MonkeyMagix's user avatar
6 votes
1 answer
131 views

Copy SQL Server Databases

I am looking to "move" databases to different servers with minimal disruption to data and service. These databases vary in size from 5GB to 140 GB. I've seen and even used some of the various data ...
Black Dynamite's user avatar
4 votes
1 answer
5k views

MSSQL: Restore a DB to the latest file in a backup set

I have a MSSQL 2008R2 DB in SIMPLE recovery mode that is periodically backed up with BACKUP DATABASE MyDB to DISK = 'Z:\MyDB.cbak' WITH COMPRESSION This runs periodically, creating multiple ...
DrStalker's user avatar
  • 7,036
1 vote
3 answers
1k views

Spoof database connection to be local instead of remote

I am trying to connect one of our clients "as is" programs to a remote database instead of a local one, they think that they have coded it to work that way, but for some reason the program ...
spydon's user avatar
  • 133
7 votes
2 answers
35k views

dbcc checkdb('XYZ', REPAIR_ALLOW_DATA_LOSS) indicating that XYZ is already open and can only have one user at a time

I have a DB, XYZ, that had a corrupt log file and now since the log file is totally unusable this is rendering this specific DB unusable and I need to be able to rebuild it. I've already done a lot ...
Christopher Bruce's user avatar
0 votes
1 answer
721 views

SQL for duplicating parent and children records

I'm trying to figure out the best way to create a SQL statement (in SQL Server) to duplicate a parent record and all the children records. I have the below as an example; -- duplicate the order ...
user2638607's user avatar
1 vote
1 answer
213 views

Unable to change schema of a Publication Database using TSQL (Ready-roll): being forced stop replication

I am trying to apply schema changes using T-SQL (using Ready-Roll database source control tool with Octopus Deployment) to a Publication database however it is forcing me stop Replication for the ...
Daniel's user avatar
  • 11
1 vote
1 answer
439 views

Information on TSQL DelBkUps parameter

We are using a TSQL script to back up our database every night, and in this scrip it uses -DelBkUps 1DAYS to remove the old disk copy of the backup. However we are running out of disk space at the ...
sec_goat's user avatar
  • 169
3 votes
3 answers
5k views

if I select more than 15 fields, I get catastrophic failure

Using sql server 2012 I am connecting to a linked server with Pervasive SQL on it. When I do select * or select field1,field2,field3....field15 I am getting this error: Msg 7399, Level 16, State 1, ...
Alex Gordon's user avatar
0 votes
1 answer
491 views

MS SQL Server 2008 R2 downloads for practice

I plan to download MS SQL Server 2008 R2 SP1 - Express Edition. I know I need one of the two applications to download with it: 1) SQL Server 2008 R2 Express with Tools and 2) SQL Server 2008 R2 - ...
Allan D's user avatar
2 votes
1 answer
18k views

SqlCmd : Login timeout expired from localhost

I've setup the instance SQLEXPRESS via SQL Server 2008 R2 installation, added a security login with all server roles, one called 'sqluser'. The server authentication is SQL Server and Windows ...
mschr's user avatar
  • 48
1 vote
1 answer
279 views

Can I split open/divide a large MS SQL disk media set?

MSSQL 2005 An old maintenance plan was backing up a database to a single disk based media set with append. It contains numerous full backups of about 2GB each. I now have a single media set file ...
iWeasel's user avatar
  • 161
4 votes
1 answer
109 views

Restore database from backup file, where file name matches reg expression

I am doing the below : RESTORE DATABASE UAT FROM DISK = 'E:\Databases\backup\MY_LIVE_20120720_070001.bak' WITH REPLACE But I want to be able to use a file location that ignores the numbers in the ...
NimChimpsky's user avatar
18 votes
1 answer
55k views

How do you get the minimum and maximum memory allocation of a SQL instance using T-SQL?

I'm managing about 90 SQL Server instances and need a query to determine how much memory has been allocated to each instance. Please note, I'm not asking how to set it, just to see what it's currently ...
token's user avatar
  • 295
1 vote
2 answers
3k views

SQL Server 2008 - Backup Databases with more than 50 characters

I am using T-SQL to backup my MS SQL 2008 databases: BACKUP DATABASE @name TO DISK = @fileName The problem occurs when it comes to the databases with their name length greater than 50 characters ...
Jonathan Rioux's user avatar
0 votes
1 answer
307 views

Creating a SQL Server 2005 User Login to Backup and Restore on a Single Database

I have a SQL Server 2005 database server with multiple databases on the server. I need to create a user login 'test1'with the following restrictions: Login 'test1' should be owner of database 'ABC' ...
user avatar
2 votes
1 answer
2k views

How can I create a database backup replacing the previously created backup file?

If I backup my SQL Server 2008 R2 database with the following command set @BackupFileName = N'C:\backup\Production-db.BAK' BACKUP DATABASE [Production-db] TO DISK = @BackupFileName and run the ...
Adrian Grigore's user avatar
1 vote
1 answer
84 views

SQL Server database backups storage

This is rather basic question. We do backups of all the databases on the server and size around 20GB every week. All that is scheduled (shrinking,Backing up) We store them on Network drive. Now ...
evenprime's user avatar
  • 111
0 votes
1 answer
385 views

Error on creating job SQL Server 2005

Error on creating job: Unable to cast object of type 'Microsoft.SqlServer.Management.Smo.SimpleObjectKey' to type 'Microsoft.SqlServer.Management.Smo.Agent.JobObjectKey'. (Microsoft.SqlServer.Smo) ...
Kashif's user avatar
  • 193
0 votes
1 answer
96 views

MSSQL2005: is there a sproc to set the default distribution agent profile?

I'm trying to work out how to set the default profile for the distribution agent programatically using t-sql. I see there is the sp_help_agent_profile and sp_help_agent_default sprocs which allow you ...
simon's user avatar
  • 714
1 vote
3 answers
381 views

T-SQL query to schedule the back-up by using Transactional logs!sql server 2008

Hello i am new to sql server and i don't know any thing about backing up database using tsql i am trying to find out the procedure to do following but unsuccessful. T-SQL query to schedule the back-...
pixelerator's user avatar
0 votes
1 answer
103 views

Does SQL Server/ T-SQL really adhere to E F Codd;s Relational Model of Databases? [closed]

The relational model as proposed by Codd heavily relies on Set Theory and Predicate Logic. Does SQL Server really adhere ?
Maximusawesome's user avatar
0 votes
2 answers
318 views

How to keep Ms-SQL database always UP: mirroring or replicationg?

I have several Tb databases in the Windows Server 2008. I would like to keep alive the service when the server is failing or the raids are needs to be rebuild. Which model to choose Replication or ...
Arman's user avatar
  • 595
1 vote
1 answer
1k views

GRANT PERMISSIONS ON SQL Server 2008,

I got the following issues while querying a database, and somehow I am not yet able to resolve it. 1. The SELECT permission was denied on the object So I executed the following command on SSMS ( I ...
user67714's user avatar
  • 357
1 vote
1 answer
1k views

SQLS Timeouts - High Reads in Profiler

I've audited a SQLS2008 server with Profiler for one day.. the overhead didn't seem to trouble this new client my company has. They are using a legacy VB6 application as a front-end. They're ...
lb01's user avatar
  • 113
0 votes
1 answer
8k views

Attaching MDF File that appears to have been truncated by the OS

I've got an MDF and LDF file from a dead server that I'm trying to attach to another instance of SQL Server. However running the following create database statement USE [master] GO CREATE DATABASE [...
Robb's user avatar
  • 103
0 votes
1 answer
708 views

Verify SQL Server Mirroring failover is successful

We have database mirroring configured as "high safety without automatic failover" on 23 databases. Both partners contain principal and mirror databases. I created two scripts that would failover ...
Ddono25's user avatar
  • 165
0 votes
1 answer
53 views

Automatically drop FK's to re-create a table and then automatically put the FK's back

I have a number of incidents where SSMS tells me table recreation is required, even for something simple like making a column nullable. If this table is referenced by FK's, I would ideally like to ...
ProfK's user avatar
  • 493
0 votes
3 answers
2k views

query maintenance plan schedule

can I query the schedule of a maintenance plan? I want to automate checking that backups were run. Thanks
user avatar
0 votes
1 answer
343 views

how to show table data as columns in tsql

I have 2 tables in sql-server 2005 express DB 1. ItemSize Table CREATE TABLE [dbo].[ItemSize]( [ID] [int] IDENTITY(1,1) NOT NULL, [iSize] [int] NULL ) ON [PRIMARY] 2. SalesLog Table CREATE TABLE [...
Raj's user avatar
  • 145
1 vote
1 answer
225 views

T-SQL Maintanance Plan

This runs as a weelky Maintanace Plan but I am not sure what it actually does. Any clues? declare @dt datetime select @dt = getdate()-30 exec msdb.dbo.sp_delete_backuphistory @dt EXEC msdb.dbo....
Andy 's user avatar
  • 199
3 votes
2 answers
1k views

SQL 2008 - Transaction log is full

We have some issues with the transaction log files We have SQL Server 2008 Our situation: Every night, we have many jobs that runs on the server by SQL Agent Some jobs stop because the transaction ...
Cloudlucky's user avatar
0 votes
2 answers
146 views

Cannot drop a table in SQL 2005

I have a SQL Server 2005 SP3 box that one of my developers created a temp table on that we cannot seem to remove because it somehow got brackets in the name of the table? SELECT Name, object_id FROM ...
David Mathis's user avatar
1 vote
1 answer
2k views

How do I get SQL Profiler to show statements with column names like 'password'?

I'm profiling a database just now and need to see the UPDATE and INSERT statements being executed on a particular table. However, because the table has a 'Password' column the SQL Profiler is being ...
Kev's user avatar
  • 7,897
1 vote
1 answer
2k views

T-SQL for autogrowth of multiple data files

I can't seem to figure out the problems with my script to alter SQL Server 2008 database and file growth. There are two data files and a log file, all which need to have Autogrowth ON. Does this look ...
Ddono25's user avatar
  • 165
0 votes
2 answers
5k views

SQL Passing a List<int> as a SqlCommand Parameter

can i pass a List into a SqlCommand as a paramter? DELETE FROM MyTable WHERE Key IN @MyParam command.Parameters.AddValue("MyParam",MyList); i realize i could just loop over the list but i was ...
KellCOMnet's user avatar