Most voted "sql" questions
Structured Query Language (SQL) is a language to query databases. Questions should include examples of table code and structure. This tag refers to the default language, not to be used for questions about the implementation of specific DBMS (such as Mysql, Postgresql, Oracle, MS SQL Server). In this case use the specific DBMS tag. Answers to questions marked with ANSI SQL should use SQL as much as possible.
Learn more…6,771 questions
Sort by count of
-
17
votes2
answers3105
viewsWhat is the question mark in a query?
Use ? in a query really avoids the SQL Injection? Avoids 100%? I saw this code and I heard many people talking about it, saying it helps in this case and how to use it? Could someone give a better…
-
17
votes3
answers8471
viewsIs a subquery in SELECT calculated for each result or just once?
Based on this example, where the result will be used to calculate the percentage of occurrence of each 'guy', which approach is more efficient/faster? Use a subquery in the SELECT to calculate the…
-
17
votes3
answers960
viewsHow to find a String from Regular Expressions
I have a field in the SQL Server 2014 database that stores the client address. The problem is that everything is stored in a single field varchar. Here are some real examples: Antonio José Nerchis…
-
17
votes3
answers1699
viewsWhy doesn’t "= NULL" work?
In the SQL Server, by fetching all records with a given field with value NULL, if I do so no record is returned: SELECT * FROM clientes cli WHERE cli.cpf = NULL But if you use the following syntax:…
-
16
votes2
answers15027
viewsHow can I refer to the heaviest queries in SQL Server?
In the SQL Server database, how is it possible to know which queries have consumed the most resources of the database in its execution?
-
16
votes2
answers2309
viewsDifference in Indice Unique and Unique Constraint usage in Sql Server?
I would like to know the behavior/differences between a Indice Unique and Unique Constraints to the Sql Server ? Many may think that it makes no difference in the database, but it does! And not only…
-
16
votes2
answers13578
viewsMysql error "expects Parameter 1 to be Resource, Boolean Given in"
$query = "Select * from servico where ID_SERVICO = $id"; $result = mysql_query($query); if($row = mysql_fetch_array($result)) { $nome = $row['NOME']; if($nome == 'Marketing') { include…
-
16
votes4
answers8313
viewsIs using addslashes against SQL injection safe?
Use the addslashes() is it really safe against SQL injection? If not, tell me why. I’ll wear mine like this addslashes() <?php $id = addslashes ( $_GET ["id"] ) ; /* Adicionei as barras */ echo…
-
15
votes5
answers29661
viewsHow do I know if a column exists in an SQL Server table?
I am trying to add a new column to an SQL Server table, and I want to know if it already exists or not. I have tried something like this: IF EXISTS( SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE…
-
15
votes3
answers70810
viewsWhat are the appropriate data types for columns like address, email, phone and mobile phone for SQL database?
What kind of data are recommended to create the following fields: address, email, mobile number/phone?
-
15
votes3
answers22703
viewsWhen is the use of composite primary key recommended?
A key simple is associated with a single value, or field, of the record. A key composed corresponds to the combination of two or more keys, and may be required to eliminate ambiguity by forming a…
-
15
votes3
answers1209
viewsWhat is SQL? How to use?
I already know at least that SQL has relation with database, with the query of values in database. But it’s not clear what would be SQL. What would you use this resource for? And how do you use SQL,…
-
15
votes3
answers2752
viewsWhat are indexes in SQL Server for?
For what the index serves, I know it improves performance, but what the database does behind that improves this performance. When is it recommended to use? And where should I use an index?
-
15
votes1
answer2041
viewsSQL LIMIT parameterized in PHP with PDO
A few days ago, I stopped using the functions mysql_*(already obsolete), and I switched to PDO. I have a function that does query database, but I’m having some problems using the LIMIT with Prepared…
-
15
votes1
answer7582
viewsWhat is the advantage of using CHAR instead of VARCHAR?
What is the advantage of using CHAR instead of VARCHAR in database since the advantages of VARCHAR exceed those of CHAR (if it has? ). There is time difference of field size definition since VARCHAR…
-
15
votes1
answer1791
viewsHow to apply Dexes to improve the performance of the queries?
I’m looking to increase the performance of my database, which has over 1 million records. Research I have undertaken Sobre index link1 Cluster-wise link1 Link2 Doubt The idea of cluster it seemed…
-
15
votes4
answers332
viewsIn relation to object orientation, should queries have a class of their own or can they stay in a specific class?
What I have is this: a user class and a connection class with the bank. I need to insert a user into a database, the query "insert into usuarios values (..)" should be in my user class or in the…
-
15
votes3
answers15156
viewsList all triggers in SQL Server
Is there any command, that lists all the triggers from a database in SQL Server?
-
15
votes2
answers10671
viewsWhat’s the difference between Union and Union All?
What’s the difference between UNION and UNION ALL? If possible, include examples of use.
-
15
votes2
answers1617
viewsWhat is LINQ technology?
Today reading some contest questions, appeared one in which it was LINQ technology. Without delving too much into the research I noticed a number of quotes as: LINQ to SQL LINQ to XML (C#) LINQ to…
-
15
votes4
answers15459
viewsWhat is the difference between LIKE, IN and BETWEEN in Mysql?
I’m having doubts about the difference and use of tags LIKE, IN and BETWEEN in Mysql. When to use tags and example?
-
15
votes3
answers4552
viewsUse VARCHAR(255) for all fields or choose the best size for each field?
Assuming the following fields (for example): Nome, Rua, Cidade ,UF. The Nome would be the client’s name. There are people with 2 short names or people with 5 or more names, so it is possible to have…
-
15
votes4
answers2051
viewsDropping indexes or Foreign Keys in a table can slow the query?
What I always read some tutorials talking about Mysql and I’ve also heard from some fellow programmers is that the lack of indexes or foreign keys in a table can make a query slow. For example, I…
-
14
votes6
answers11304
viewsHow to get distance given the coordinates using SQL?
I’m doing a function in php, in which, given a GPS coordinate, it will search in the database the recorded locations, which are not necessarily fixed, within a certain distance. My question is, how…
-
14
votes4
answers1643
viewsIs it really necessary to define constraints in the database?
Ruby on Rails seems to have been thought of considering that it is not necessary to define constraints (as Foreign Keys) in the database, just define them via application. Usually the only…
-
14
votes2
answers352
viewsWhat does the operator = mean in C#?
I have a function in C#, where I decrypt a string and need to convert into a function in SQL Server for technicians to be able to work with the decrypted value. There is a foreach, I don’t…
-
14
votes3
answers2619
viewsCan subqueries decrease performance? Myth or truth?
Well, I usually just work with frameworks. I work with frameworks MVC and I usually use Orms to query the database. In my case I use Laravel, but I’ve used other frameworks, and had the opportunity…
-
14
votes3
answers3192
viewsWhat is the difference between Full Text Search and LIKE?
I’ve heard a lot about the term Full Text Search (FTS) lately, and I’ve been told that I should use this instead of drafting the queries with LIKE. But how to use the Full Text Search? What are the…
-
14
votes1
answer16891
viewsWhat does COLLATE LATIN1_GENERAL_CS_AI do?
I’m asking this question because I came across this reply by @Sorack; I didn’t understand what influence COLLATE LATIN1_GENERAL_CS_AI had the result, I’ve seen some answers here on Stackoverflow and…
-
14
votes4
answers2496
viewsPerformance of COUNT(*) and COUNT(1)
What’s the difference between COUNT(1) and COUNT(*) in an SQL query. For example: SELECT COUNT(1) FROM USUARIOS; and SELECT COUNT(*) FROM USUARIOS; Is there any difference of interactions within…
-
14
votes2
answers314
views=, BINARY, LIKE, LIKE BINARY, REGEXP, SQL binary grouping
Reformulation of the question based on @Gabrielhenrique’s answer and research: What is binary grouping in a string column in the table? BINARY serves to make a case-sensitive search and LIKE…
-
13
votes7
answers180098
viewsFormat decimal places directly in the SQL command in Firebird
I have a table ESTOQUE containing a field called QTDE, this field has 3 decimal places. What would be the command to return directly from SQL formatted with 3 houses? Because the integer values are…
-
13
votes3
answers3561
viewsJava and Offline Databases
I need some help with a Java database. I want to make a database that the program generates a file, such as "database.db" and this file I can access without any internet connection, using only the…
-
13
votes5
answers53548
viewsMysql decimal value
I am trying to insert decimal value in mysql database, wanted to put these values for example: 1.500,00 Thousand, hundred and ten What is the type of column I must declare?…
-
13
votes3
answers1955
viewsPre-process large text files in R
I am writing a script, which I will make public, to open the micro-data of RAIS (dehydrated, available here) in R using Monetdb. However the bank does not accept vígula (,) as decimal separator.…
-
13
votes3
answers25273
viewsTable and column nomenclature
For at least four years I’ve been working with the following table and column nomenclature which is exactly like this: The column name will always be tableName + column name =…
-
13
votes3
answers9451
viewsWhat is the meaning of the sign || '-' || in SQL
I am performing a query in an Oracle database and come across this symbology || '-' ||, in my query. I’d like to know the meaning? Select xf0cdloc || '-' || XN4CDEMP AS LOCOMOTIVA, From Trem…
-
13
votes2
answers722
viewsHow index selectivity works
Reading about indexes I recently came across the term "selectivity". Some places said more selective fields should come first on the index, others say no or that it depends. I have the following…
-
12
votes2
answers7355
viewsIs it better to parameterize your Preparedstatement even if the value is fixed?
I always read the blog Java Revisited and I’ve been reading the article today Why use Preparedstatement in Java JDBC - Example Tutorial. At a certain point the author talks about parameterization of…
-
12
votes5
answers6123
viewsPhysical Exclusion vs Logical Exclusion
What is the advantage of making logical exclusion (Ex: Set a flag indicating that the record is active or not), instead of performing physical exclusion? Is it common practice? It’s safe? Derived…
-
12
votes4
answers3355
viewsPHP login with permission levels
I have a problem with my code to separate logins. I want when a login with Rank = 1 it redirects to a page, and when the Rank is = 0 go to another. I tried to do it but I didn’t get it because he…
-
12
votes4
answers2869
viewsIs it recommended to use natural primary key?
Natural primary key is one that contains real data, not just a random value, but an integer. Example: // comum CREATE TABLE pessoas ( id INTEGER PRIMARY KEY, cpf INTEGER NOT NULL, // outros campos…
-
12
votes1
answer998
viewsWhat’s the difference between "ON" and "USING"?
Considering two ways to declare one INNER JOIN, we have: SELECT * FROM tabela1 INNER JOIN tabela2 ON tabela1.cd_tabela1 = tabela2.cd_tabela1; and SELECT * FROM tabela1 INNER JOIN tabela2…
-
12
votes1
answer10002
viewsDifferences between Natural Join and Inner Join
What characteristics differentiate a consultation performed with the use of Natural Join other with the use of Inner Join? Is there any question related to performance or any other condition that…
-
12
votes3
answers2689
viewsHow to rename all tables in a Mysql database
I have a Mysql database with several tables and am migrating to another database. I have Client and must stay Cliente_pe I have product and should stay How can I accomplish this without however…
-
12
votes2
answers15638
viewsWhat is the difference between Function and Procedure?
What are the differences between the two, and examples of where and generally are used.
-
12
votes2
answers815
viewsHow does the logic of Where in the Entity Framework work?
I’m studying C# and I just made my first query in the Database: using System; using System.Data.Entity.Core; using System.ComponentModel.DataAnnotations; using…
-
12
votes2
answers736
views -
12
votes3
answers2531
viewsHow to select all columns except one in particular?
There is the possibility to select all columns of a table: SELECT * FROM wp_rw_programacao WHERE id = $id But I need to eliminate the result of the column id. It is possible?…
-
12
votes1
answer398
viewsWhy does the SQL language vary from DBMS to DBMS?
I was used to using SQL for Web projects, always using Mysql. One day I had to write a C++ program that used databases. At first I chose Sqlite but needed other computers in the network to connect…