Questions tagged as 'sql-server'

4
answers

Is it possible to reference a column other than a primary key in another table?

For example, I want to reference the id_2 of Table 1 in Table 2, I know I can do with primary keys but with other columns I do not know if it is possible. Table 1: id (primary key of table 1), id_2, name Table 2: table_id2 (primary key of...
asked by 07.05.2014 / 16:20
3
answers

In trigger we have INSERTED, DELETED, BUT and "UPDATED"?

Example scenario: I have the table / fields: documentos id documento pessoa item qtd valor The system gives INSERT and then UPDATE in this table in a contin...
asked by 28.08.2018 / 15:27
1
answer

How to kill, remove or not initialize SQL Server master bank?

I woke up in the morning and gave a "Run" on top of the " cotacao " bank, the bank I'm currently working on. Then the login screen entered and when I logei the bank that received the tables was the master and not the " cotacao "....
asked by 22.11.2017 / 11:06
1
answer

Reset Auto-increment SQL Server

Good morning, I created a new table in SQLServer and I'm testing some scripts to popular the table and I came across the following situation, in my tests I'm doing the insert in the table checking the information and if they do not agree I ma...
asked by 22.02.2018 / 16:29
3
answers

Query on sql query

I have a question. I think it's not very complex, but I could not solve it. For example, I have this query: select * from Paciente where ClinicaID = 3 Your result would be these 3 records: NomePaciente HoraAtendimento Ativo Clinica...
asked by 28.11.2017 / 23:55
3
answers

Copy bank record

I used the following query to attempt to 'copy' a record insert into valores select * from valores where id = 1 However, I get the following message:    An explicit value for the identity column in table 'values' can only be specified wh...
asked by 13.04.2015 / 21:18
1
answer

What is the best type to store area, volume, perimeter? [duplicate]

Decimal , Numeric or Float . What is the best option to store area or volume? I would use Decimal, but I would like to see the views of others as well. It does not seem like it, but the right kind or the closest of that make...
asked by 21.11.2017 / 17:56
2
answers

How to run the million-line INSERT script in SSMS?

I'm trying to run a script in the SQL Server Management Studio (SSMS) with more than 1 million records and the following error occurs:    Message 10738, Level 15, State 1, Line 1032       The number of line value expressions in the INSERT s...
asked by 14.11.2017 / 19:42
3
answers

Over with Group by

I have a query that I use to return as an extract, accumulating the registry values to registry: SELECT TOP (100) PERCENT Mes, Credito, Debito, Sum(Credito - Debito) over (ORDER BY Emp_id, Mes) AS Saldo , Emp_id FROM viewFluxo ORDER BY...
asked by 06.09.2017 / 19:29
2
answers

How to update all records of all tables that have FK from a table

I have the following tables: CREATE TABLE Contrato ( [Id [int] NOT NULL IDENTITY, [Nome] [varchar](150), [Ativo] [bit] PRIMARY KEY ([Id]) ) CREATE TABLE [dbo].[ItemContrato] ( [Id] [int] NOT NULL IDENTITY, [ContratoId] [int], [No...
asked by 25.08.2017 / 20:51