Most voted "sql-server" questions
SQL Server is a relational database management system from Microsoft. Use this tag for all SQL Server editions, including Compact, Express, Azure, Fasttrack and PDW.
Learn more…2,752 questions
Sort by count of
-
2
votes1
answer1350
viewsError executing bcp command inside a precedent
When I execute the command: DECLARE @cmd varchar(1000); SET @cmd = 'bcp "select [colunas] FROM [usuario].dbo.[tabela] " queryout "\\***\SQLServer\text.txt" -c -UTF8 -T -S***'; EXEC xp_cmdshell @cmd;…
-
2
votes1
answer849
viewsHow to select a port to connect to SQL-Server Remote
I have the following problem, my SQL server is with port 1433 open and communicating correctly, but my client has a firewall that blocks all incoming and outgoing ports of computers connected to the…
-
2
votes1
answer728
viewsSelect column type that comes in a SELECT
Hello, my question is this:: I have a Select in Sqlserver of two tables with Inner Join, they return me a set of 5 columns. I would like to know how to list the type of these columns. I know you…
-
2
votes2
answers6591
viewsError trying to establish connection between SQL Server 2014 and Visual Studio
I’m having problems connecting Visual Studio 2010 [c#] with Sql server 2014. I followed some tutorials but did not succeed. Why is such a mistake happening?…
-
2
votes1
answer546
viewsRandom results in SQL queries without repeating (Scroll Infinity)
I’ve had this problem for a long time and I can’t fix it. I have a page with infinite scroll that returns some rows from the database, but the results most often repeat. I’m using the following…
-
2
votes1
answer235
viewsCan the automatically generated . mdf database in App_data be used in production?
The automatically generated database within the App_data folder in projects Asp.Net MVC and Web-Api can be used in production or is a test basis only?
-
2
votes2
answers1050
viewsOrphan records , checking in another table
I have a table of photos: tbl_fotos int_ID (Pk, int) int_IDProduto (int) str_foto (varchar(40)) and a table for products tbl_produtos int_ID (PK, int) I want to know how many photos there are…
sql-serverasked 10 years, 4 months ago Dorathoto 7,426 -
2
votes1
answer788
viewsRow sorting in a table with SQL SERVER
I have a table (Customer) example: ID Nome Order 1 Joao 1 2 Ana 2 3 Marta 3 4 Joana 4 The goal is to sort the contents as follows: I get the ID (@ID) from the position to change and the new position…
-
2
votes2
answers210
viewsQuery performance with date range
Assuming I have a database table with 10000 data and each record is registered with dates between 2013 and 2014. A query like this: SELECT CAMPO_DATA FROM TABELA WHERE CAMPO_DATA BETWEEN…
-
2
votes1
answer387
viewsMulti-line update SQL server 2008 + PHP
How I can do multi-line updates with PHP on sql server? I have a structure similar to that, but with many lines: ID nome vencimento 11 | Joao | 20/02/2014 12 | Arthur | 21/02/2014 13 | Ana |…
-
2
votes1
answer215
viewsRemote connection of SQL Server 2008 Express
I have 2 servers (a physical and a local VM) in which one of them has SQL Server 2008 R2 Enterprise Edition (physical) installed and the other (local VM) I have SQL Server 2008 Express Edition.…
-
2
votes2
answers174
viewsWhat SQL server command to list the user’s transaction Isolation level
Is there any command I can run on sql server to list the user’s Isolation level transaction?
-
2
votes3
answers15502
viewsSQL Server command to list active transactions
Which SQL Server command lists the currently active transactions?
sql-serverasked 10 years, 2 months ago fasr 143 -
2
votes1
answer1633
viewsHow can I get a date 60 months ago?
I want to get some date 60 months ago. I’m in a project that shows only the files sent 60 months, but it’s 60 months and not 5 years, maybe it doesn’t make any difference. Any idea? I tried using…
sql-serverasked 10 years, 2 months ago RenatoMateusX 99 -
2
votes1
answer3962
viewsHow to bring only results from the last 30 minutes
I have a table in sqlserver that will be logged error logs in which it contains the following fields: sequence date message I would like to know how to get the results of the last 30 minutes…
sql-serverasked 10 years, 1 month ago Jean Braz 187 -
2
votes3
answers162
viewsCreate tables randomly
My question is this:: I have a table containing 25 records of people’s names. But I need to divide it into 5 groups of 5 people randomly. Being a table 'Group A' with 5 people, another table 'Group…
-
2
votes1
answer2608
viewsAssign execute command to a variable
I need the return of the execute command to be assigned to the @PAGO variable because I will insert it into a temporary table only what returns is the script and not the value. DECLARE…
-
2
votes1
answer109
viewsBackup Database Sqlserver
I know that to perform a backup in SQL Server just use: BACKUP DATABASE nome_database TO DISK = 'endereco\nome__arquivo.bak' But does anyone know how to backup all Databases together? Each one in a…
-
2
votes1
answer855
viewsError 229 in SQL Server
I created a user in SQL Server 2014 and then logged in with the created user. When I went to update the folder Table he appears this message: That is, the user I created is not allowed to view the…
sql-serverasked 10 years ago wladyband 4,694 -
2
votes1
answer211
viewsIs there a command to change a user-created type in Sql Server?
I created a type in my Sql Server database: CREATE TYPE [dtNumero] FROM [numeric](18, 5) NOT NULL Is there a command for you to change this type, for example the accuracy?…
-
2
votes3
answers16754
views"Must declare the scalar variable" error
When I run the following Procedure, Sqlserver gives the error: Must declare the scalar variable error "@VDIAPARALYZED". Procedure: BEGIN SELECT @VDIAPARALISADO = COUNT(F.DATA) FROM ED_FERIADO F…
-
2
votes1
answer628
viewsGenerate database backup via application
In my project I connect to the database. Is there any way I can do the backup from my database via Asp.net mvc 5 and keep that backup in a directory, either at the project root or in a folder in a…
-
2
votes2
answers89
viewsHow to find a value in several fields
In my bank I have 3 columns for phone, I need to know if the value is in any of the 3 fields, what is the best way to mount this select?
-
2
votes3
answers516
viewsColumn outside the SELECT WHERE condition
I need to make a query that returns a column with the amount of orders that the customer made within the period past in the WHERE and put together another column with the total orders that the…
-
2
votes2
answers931
viewsSelect returns nothing at all
I have the following method: public DataTable Select(bool all = true, string campos = null) { if (all && campos == null) _sql.Append("SELECT * FROM "); else _sql.Append("SELECT " + campos +…
-
2
votes1
answer46
viewsReplace in Date inside a FOR
I want to return the last 12 months, the day should come as 01 and need month and year. ex: 2014-12-01 2014-11-01 NOTE: I put yyyy-mm-dd only by a pattern of mine. I’m doing like this: DECLARE…
-
2
votes1
answer505
viewsBegin transaction is blocking my entire database
I got a problem, I got a problem script php that reads large XML files. Before I start inserting this data I make a Begin transaction and in the end the commit, but throughout the process that can…
-
2
votes2
answers441
viewsRecreate tables without dropping
I have an already populated table. In it there is a field not null, which I need to set to null. In graphical mode does not accept and says I have to recreate the table. Is there a way to do this…
-
2
votes1
answer209
viewsIF in Storedprocedure within a select, remove sp_executesql @query
I have a Storedprocedure that unfortunately only because of an IF has ceased to be a select and turned everything into a VARCHAR statement and then I run it, losing one of the main benefits of MSSQL…
-
2
votes1
answer1272
viewsHow to change the name of the target database when performing the restore? (Restore C# .net class)
I am backing up and re-storing an SQL Server database using the C# NET Backup and Restore classes with Smo. The problem is that after backing up the database with the name, for example "Test", I…
-
2
votes1
answer1784
viewsInsert data into table with foreign key
Knowing that I have a table with the fields: [ARQUIVO_GUID] ,[XARQUIVO] ,[TAG] ,[EXTENSAO] ,[URL] ,[IS_STREAM] [ULT_ARQUIVO_VERSAO_GUID] FK [TIPO_DE_ARQUIVO_GUID] FK [DIRETORIO_GUID] FK The last 3…
-
2
votes1
answer288
viewsJoint foreign key between index field and a possible string
I am creating an application where I thought of a possibility to insert all existing addresses in the system in a single table, both for users, customers, suppliers etc. the structure of my table…
-
2
votes1
answer2651
viewsChanged RU context, but without updating database structure
I’m using the free hosting service from mee on a free plan. So far so good, everything worked out in a good. But after I made some changes to my database, their database just doesn’t work, it keeps…
-
2
votes1
answer519
viewsHow to block editing of a record when it is edited by another C#user
In a network system (Several using the same database), how do I know if any user is already editing the record. Because if in case two computers edit the same record at the same time, a problem…
-
2
votes1
answer249
viewsError when exporting SQL Server database to another Server
I have a database on an SQL Server Web Edition (64-bit) server (11.0.5556.0) and need to export it to a server with SQL Server Express Edition with Advanced Services (64-bit) (10.50.4297.0). When…
-
2
votes1
answer66
viewsMake an IF to set WHERE
I need help with a command in a proc SQL. Basically I need something like this: ... ... WHERE IF ( @Id_ProductClass IS NULL ) WHERE CLIENTPROD.Id_ProductClass NOT IN (59, 150) ELSE WHERE…
-
2
votes2
answers160
viewsBest high availability path for my need
I have studied a lot about high availability in SQL Server, in its most diverse options, that SQL Server has. But so far I could not find the solution that better meets my need. My setting: I need…
-
2
votes2
answers2828
viewsCURSOR vs table variable type
I’m facing one of those situations where I need to perform an action for each line resulting from a query. This way I have two options, use a Cursor or a Table Variable, but the two seem very…
-
2
votes1
answer42
viewsSqlserver 2012 - Column '' in table '' is of a type that is invalid for use as a key column in an index
After seeing this error when creating a NONCLUSTERED index I wondered if it would really be necessary to create this index in the following scenario: I have a table with 11 columns, a column I save…
sql-server entity-framework entity-framework-6 sql-server-2012asked 9 years, 6 months ago Ricardo 5,680 -
2
votes1
answer99
viewsReset to auto increment
I have a problem at my base of fingers. I have the sending code as auto increment but whenever I delete a sending code the value not reset or I do not restart will always increase. I wanted to know…
-
2
votes1
answer3605
viewsA cursor inside another sqlserver cursor
I know I could do a tab1 Join with tab2, but that wouldn’t be the case, I need both cursors. When I run I get error from: A cursor with the name 'cursor_tab2 ' already exists. The cursor is already…
-
2
votes1
answer1718
viewsHow to create schema and use it in table creation
I need to create some tables, but have that structure. For the tables of Registers I put: Registration.Company, Registration.UF, Registration.Address and so on. For the Logo tables I do: Log.Hits,…
sql-serverasked 9 years, 6 months ago pnet 14,727 -
2
votes2
answers1940
viewsUpdate with select in time table
People, I need to create a temporary table with 2 fields (codProduct and codBarra), and with these temporary table records, I need to update to my main table. How do update with select in the…
sql-serverasked 9 years, 5 months ago Raimundo 29 -
2
votes1
answer894
viewsHow to counter "blocks" in Sql Server
I would like to know how an accountant would look in an SQL query for the following situation: I have the columns matricula, date and time worked where I would like to create another column with the…
sql-serverasked 9 years, 5 months ago Rafael 85 -
2
votes3
answers2032
viewsSelect from the last records sorted by 1 field
I have the following table structure The goal is to get the last 3 oldest records (oldest date) ordered by Name. Today I’m using subselect: Select * from (Select top 3 from TB order by Data desc) A…
-
2
votes3
answers183
viewsReturn the difference between the last two records
What I need to do is in this image. How I do? This is the query I did and it’s coming empty and I don’t know why. SELECT event_type, value from teste t1 Where exists (select event_type, value from…
-
2
votes1
answer2242
viewsAdd Column as Primary Key
I ran the following script: CREATE TABLE [dbo].[horario]( [Ano] [int] NOT NULL, [CodigoTurma] [varchar](5) NOT NULL, [Ordem] [int] NOT NULL, [Professor_Id] [int] NOT NULL, [Matriz_Semestre] [int]…
sql-serverasked 9 years, 5 months ago Jedaias Rodrigues 6,718 -
2
votes2
answers9331
viewsChange numerical field accuracy SQL SERVER
I am facing a problem when changing the accuracy of a numerical column in an SQL SERVER table. The countryside is like NUMERIC(5) and would like to change it to NUMERIC(5,2), but is presenting the…
sql-serverasked 9 years, 4 months ago Renan Santos 35 -
2
votes1
answer655
viewsScript for Run in Function
I’m performing a conversion on some comic objects where they are with a fixed name of the database. Example: select * from banco.dbo.tabela ... In this case, we are changing this banco fixed, by a…
-
2
votes2
answers90
viewsReturn columns that accept Boolean in a table
I need a query that brings the name of the columns in a table that accept boolean. Ex: In the table clientes, have the fields casapropria (1 for yes, 0 for no), temfilhos (1 for yes, 0 for no).…