Questions tagged as 'sql'

2
answers

Is it good practice to keep foreign key columns redundant?

Consider that we have the models A , B , C and D , each referencing the previous one, ie A has many B s, B has many C if C has many D s: No redundancy A | id | ... | ------...
asked by 23.06.2014 / 19:56
4
answers

Good practices for storing logs

What information should be stored? Is it a good practice to use TRIGGER in the database to store logs or via code is something safer and easier to maintain?
asked by 01.04.2014 / 21:33
1
answer

How to get the last record entered in SQL according to your date

I need to get a record of a table, where this record is what the date was entered last. Of the genre: SELECT Ped.Quantidade FROM ped WHERE data <= @data But as I have several records it returns me all, when I just want the last one in...
asked by 16.04.2014 / 13:44
2
answers

Replace in SQL - Character to keep a piece of text

I need to modify a part in the text of a table. The records for an email are [email protected] and need to change all to jf.jus.br . Only the first part of the email does not change (the xxx). I can do one update TABELA set email = RE...
asked by 19.08.2014 / 17:08
2
answers

Suggestion Migration System and modeling of individuals and legal entities in a system with Entity Framework

Well, the question is this. I have a database that has the purpose of making the cash book of a company, basically this bank has a CaixaCorrido table with columns Id , PessoaNome , DataHora , Descricao , Valor...
asked by 09.03.2016 / 15:23
2
answers

Sql Server 2014 Null Value

I am a beginner in Sql server, I am doubtful about 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 @bool returns as 0...
asked by 23.09.2016 / 23:06
3
answers

How to sort records in the query according to another sort?

I have a table with the following columns: id - manager_id - value - source - source_id By registering an "Account to Pay", I enter in this table the company's management breakdowns. Assuming that it would have to pay a certain vendor the...
asked by 10.12.2015 / 20:05
2
answers

How to do a row count (SELECT COUNT) in Linq

How to make a count of records that a query would return in Linq (Entity Framework) in C #? The equivalent in SQL is to make a SELECT COUNT(*) . Note that I want to receive the direct count of records, just like a SELECT COUNT (*) would...
asked by 21.03.2014 / 15:22
3
answers

Search between dates with between [duplicate]

I have the following search: SELECT * FROM ('agendamentos') WHERE 'age_data_agendado_para' BETWEEN "2016-08-28" and "2016-08-30" In the database, I have: But on my return, I can only search for two records, as print_r (): Arra...
asked by 18.08.2016 / 14:59
3
answers

How to delete the last record from a table?

I was using the following code in mysql: delete from aluno where id=(select MAX(id) from aluno); But the following error appears:    Error Code: 1093. You can not specify target table 'student' for update in FROM clause.     
asked by 09.08.2016 / 19:30