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
-
10
votes2
answers1392
viewsWhat are they, Readpast and Nolock?
What is READPAST and NOLOCK? I’ve seen quite a lot of the use of NOLOCK, but the READPAST I saw the use now, practically the same way, ie. FROM dbo.table t WITH(READPAST) and FROM dbo.table t…
-
10
votes5
answers972
viewsHow to get the name of the day of the week on the first day of the month?
How do I get the name (Monday, Tuesday, Wednesday...) of the first day of the month of December from the current date?
-
10
votes1
answer272
viewsComparison: CTE vs CURSOR
I do not know if this is a question that many ask, but I have always had it in mind almost always. Usually, when I need to deliver a script corrective to a customer, used only to be executed once, I…
-
9
votes1
answer5672
viewsLeft Join with lambda Groupjoin and with condition
How can I make one left join with some conditions using lambda LINQ expressions? In SQL Server have this query: select usr.Id, usr.FirstName, usr.LastName, ex.Id from User usr left join Exam ex on…
-
9
votes2
answers3219
viewsConnect Arduino to SQL Server
I’m looking to keep an updated database with the outputs of the Arduino sensors. I wonder if it is possible to connect directly the Arduino to SQL Server for sending and receiving data. Or the only…
-
9
votes2
answers144
viewsIs it redundant to use LIMIT in a QUERY whose ID is the primary key?
My question is if using LIMIT there will be some performance gain in the QUERY. Example: SELECT descricao FROM produto WHERE id = 9999 LIMIT 1 Has better performance than? SELECT descricao FROM…
-
9
votes3
answers49197
viewsHow to use the output of a select to mount another?
I built a select that concatenates a string. I want to use the result of this select in another select SELECT * FROM (SELECT CONCAT('caminho da tabela') AS caminho FROM tabela) AS result Can you do…
-
9
votes3
answers830
viewsConvert rows to columns (Pivot?)
I have a chart with 33 million phone records with the structure below: ccpf_cnpj ddd telefone tipo origem 11111111111 83 81021111 M SERASA 11111111111 83 87472222 M SERASA 11111111111 83 81023333 M…
-
9
votes2
answers2804
viewsWhat is the "connectionString" connection string?
What is after all to string connecting? In a string of connection what represents the data-source? And the provider name?
-
9
votes3
answers189
viewsSQL - Restrict query data
Good morning, I have an app in WebForms than from two DropDownList obtain data from a database in MS SQL Server 2012. At first DropDownList it will present the name of several companies in the…
-
9
votes1
answer3234
viewsWhat is dynamic SQL?
I have seen many cases where some show how to use, and others where they simply advise against using SQL dynamic. I had the following doubts: But anyway, when we should or should not use dynamic…
-
9
votes2
answers34544
viewsHow to get column names from a table in SQL Server?
Table Languages: How to select the Column Names of this table? The result would be: "Ididiome", "Acronym", and "Language".…
-
9
votes3
answers3392
views_ (underline) in consultation with LIKE
I’m making a query where I need to return all information from a given table, which contains "_R_" in the nomenclature. However, when using WHERE NM_CAMPAIGN LIKE '%_R_%' he returns me to other…
-
9
votes3
answers189
viewsLEN function, know number of characters of a number
In the example below the result of the query instead of returning 7 is returned 5. DECLARE @valor money = 10.6879 SELECT LEN(@Valor) The impression I get is that when the number is the type money ,…
-
9
votes2
answers132
viewsHow to correctly read documentation from an SQL command?
I was studying the concept of transactions and as always the reference was the documentation of Microsoft itself (in the case for the products of the same). In the link below there is the…
-
8
votes3
answers3242
viewsHow to get the last date of a day of the week in a given month in SQL Server?
Using the T-SQL language of SQL Server, how to get, for example, the latest wednesday of the month of May of a given year?
-
8
votes1
answer50072
viewsHow to get in SQL the last record inserted according to its date
I need to get a record from a table, where this record is what in date terms was last entered. Gender: SELECT Ped.Quantidade FROM ped WHERE data <= @data But since I have several records it…
-
8
votes1
answer4798
viewsSelect fields from another table with multiple foreign keys
I have 4 tables : Lojas(nomeLoja, *IDloja*, morada, telefone, email) Bancos(nomeBanco, *IDbanco*, morada) PlanoContas(*conta*, descricao) Gestao(NIB, nConta, conta1, conta2, IDloja, IDbanco,…
-
8
votes1
answer9490
viewsWhat is the difference between TRUNCATE and DELETE + CHECKIDENT?
Both perform the same action (delete + reset the PK value), but in performance what is the difference between them? Example: When you have more records it is recommended to use which form? TRUNCATE:…
-
8
votes5
answers42558
viewsHow to delete data from a table with dependencies in other tables
I need to delete data from a table that has dependencies on other tables. For example, so that I can delete a data from the person table first I have to delete a dependency that exists in the…
-
8
votes1
answer6038
viewsImplications of using Inner Join and left Join in a single select
I have some stored procedures in a SQL Server 2008 R2 database, these stored procedures have several joins, in some cases I used in it select, Inner Join and left Join, for example: Tabela Pessoa |…
-
8
votes1
answer6769
viewsMaximum number of simultaneous database connections
I am using a system monitoring solution and observe that at peak times the system has about 1500 simultaneous connections. From this data, I searched and could not find where I can check the limit…
-
8
votes2
answers19790
viewsDelete all tables from a database at once
Is there a way for me to erase an entire database at once? Isn’t it drop, is to delete only the records of all tables belonging to the database.
-
8
votes4
answers7856
viewsCalculate Total Hours by identifying Equal Time Intervals
after a bit of a break in the head, I ask for help from you to assist in the following situation: I have a problem with SQL (Sql Server 2005) calculation of hours; Basically I have to calculate the…
-
8
votes1
answer1373
viewsHow to handle duplicate key error?
How do I handle duplicate key error? I need to display message to the user that the "Item is already registered" Something like that: try{ //tenta inserir no Banco de Dados…
-
8
votes5
answers6773
viewsSeparate ddd from phone with SQL statement
I have a table with fields DDD and Phone. Some were registered correctly, others the ddd is next to the phone and need to separate. TABLE +--------------------+ | DDD | Telefone |…
-
8
votes4
answers15280
viewsCan you create an array in SQL Server?
In SQL Server Management Studio 2012 you have the possibility to create an array in a trial? I did a google search and did not find, apparently it is used such a table variable to store more than…
sql-serverasked 8 years, 6 months ago HeyJoe 819 -
8
votes2
answers88
viewsSql Server 2014 Null Value
I am beginner in Sql server, I am in doubt regarding the following code: declare @var nvarchar(50) = null declare @bool bit if (@var = null) set @bool = 1 else set @bool = 0 print @bool The variable…
-
8
votes3
answers13782
viewsChanging the data type of an sql column
Good morning. I have the spine CliTelCel char(10) on the table of Clientes, need to change char(10) for char(11). However this column already exists data, what would be the best way to proceed in…
-
8
votes2
answers2203
viewsIs a View faster than a regular Query?
When using a query of type SELECT * FROM myView is faster than SELECT * FROM (query para gerar a view acima) I have an appointment and would like to curl or make it faster, but I am in doubt if I…
-
8
votes1
answer279
viewsWhat is the best type in SQL to use with Cryptocurrency?
I am developing a system where I will store transactions of Cryptocurrencies, type Bitcoin, I can not in any way have problems of conversion and rounding, in C# I checked and the best is decimal,…
-
8
votes5
answers833
viewsHow to calculate the date and shift code?
I have a table that specifies the starting time of a work shift and its duration in minutes: codigo descricao inicio(datetime) duracao(int) S01 PRIMEIRO 1900-01-01 05:00:00.000 540 S02 SEGUNDO…
-
8
votes1
answer4263
viewsWhat is the difference between ASC or DESC in clustered indices?
When I’m going to create an index no clustered in SQL SERVER, appears in SSMS the option to choose if the option "Columns" is ASC or DESC, as shown below: It is usually used ASC or DESC for sorting…
-
8
votes1
answer2652
viewsCommand "TRIM" SQL Server
I’m working with Sql Server, and I need to make a trim as a result of a consultation. I did it this way: select TRIM(NUMERO) from ENDERECO In the Sql Server Management the command is "recognized",…
-
7
votes1
answer860
viewsSSIS loading entire XML before you start writing to SQL Server
I need to load a single large XML file (40GB+) into an SQL Server 2012 table using SSIS. I’m having problems because SSIS seems to be trying to load the entire XML file into memory before loading…
-
7
votes2
answers787
viewsHow to build a complete XML in T-SQL?
I am working on a project that returns an XML field, so far not bad. The problem arises when I have initial data coming from a query and intermediate data coming from another query. I tried to solve…
-
7
votes1
answer462
viewsUsing Cookies or Databases?
I need to create a cart where you store more than one data Example: ID_PRODUTO, ID_VENDEDOR I would like to use Cookies pro system get lighter, but I found a big problem, the Cookie stores the data…
-
7
votes1
answer244
viewsHow to support user-added columns without updating the EF model?
I have an app C# with a model Entity Framework 6 "Database First" created from the basic structure of a database SQL Server, which belongs to a third party software. Users of this software can add…
-
7
votes1
answer334
viewsSqlserver English Error Messages - (Localdb) v11.0
I’m developing an app with Entity Framework 6 using the approach Code-First. I want to configure Sqlserver (Localdb) v11.0 to display error messages in English without using SQL Server Management…
-
7
votes3
answers2562
viewsSort SQL by 1,2,3 instead of 1,10,2,3
I have a name field in a table that has the following data: 1-Course 2-Course 10-Course When ordering by name it returns 1,10,2. How to make order to bring: 1,2,10 ? Ps: The field is NVARCHAR.…
-
7
votes1
answer252
viewsGenerate database backup
In my project, I have a database that has a lot of record. So I wanted SQL Server to make a backup per day or per week. But I think the per day is better. But how can I do this script to be…
-
7
votes3
answers15498
viewsC# dynamic COMBOBOX (SQL BD table data)
I need to load a combobox with the data from an SQL DEPARTMENT table (with code and description/ the description is displayed in the combobox but what is caught is the code) I used a datasource (the…
-
7
votes3
answers190
viewsSeveral tables that should represent a single entity
I am updating a system that has eleven tables that represent a single entity, I believe by implementation error, as an example below: Entidade: Foo Tabela Foo1 - Campo1, Campo2, Campo3 Tabela Foo2 -…
-
7
votes2
answers686
viewsFull Join N-N without repeating records
I have two tables with relation N-N: ITEM_ORC ITEM_COMP | OP | Item Orçado | | OP | NF | Item Comprado | +-------+------------------+ +-------+---------+------------------+ | 1 | Lápis | | 1 | 101 |…
-
7
votes1
answer76391
viewsINNER JOIN with 3 tables
I have 3 tables Tb_contratocotista: Tb_contract: Tb_stakeholder: I would like to relate the values of the table Tb_contract with Tb_stakeholder, but the way I got it only returns the result of…
-
7
votes1
answer713
viewsDoes number of columns influence performance?
When modeling a database, the number of columns can interfere with performance? Ex: Tabela1 possui 2 campos, 1 int pk e 1 nvarchar(50) Tabela2 possui 50 campos, 1 int pk e 49 nvarchar(50) Select…
-
7
votes1
answer815
viewsHow to set the maximum disk size of a database?
How to set the maximum disk size of a Mysql, Oracle, Postgresql or DB2 database? This is how I do in SQL Server: Create Database MyDatabase on (Name='MyDatabase_Data',…
-
7
votes2
answers749
viewsTable does not appear in EDMX models
I have a problem in an application I am developing, I created the models using the ADO.NET Entity Data Model. However a specific table is not appearing follows below the script I am using to create…
-
7
votes3
answers2045
viewsInserting record and recovering ID generated by SQL Server 2012
I want to insert a record into a table, recover the ID that was generated by AUTO_INCREMENT and insert records into other tables using this ID. But, I want to do this all using the BeginTransaction.…
-
7
votes2
answers642
viewsError while trying to update table using C#
I created a form to change a table, but my update is not working. cnxCli.sel =/*"set dateformat dmy \n"+ */ "update Cliente" + "set Nome = '" + txtNome.Text +"'," + "Rg = '" + mskRg.Text + "'," +…