Wrong executed SQL Statement error - sql

TL;DR: How do I make the table refresh with the new, updated columns?
Hi, I'm getting an error which states that I have invalid column names. The column names which are invalid have been deleted before hand and updated then.
When I refresh the table's data, the error is displayed again stating: SELECT TOP [1000], Error Source: .Net SqlClient Data Provider and the invalid column names.
The error is straight forward, but how do I manage to change the "default" refresh query of the table? I checked the table from SQL Managment Studio and Visual Studio and everything seems right... it's just that this query is not adapting to the update which I done to the table. This table had a foreign key with another table but I'm sure that I deleted any links with other tables.
Just in case this is the code of the table:
CREATE TABLE [dbo].[Receipt] (
[receiptID] INT IDENTITY (1, 1) NOT NULL,
[employeeUser] NVARCHAR (50) NULL,
[purchasedProductID] INT NULL,
[productName] NVARCHAR (50) NULL,
[clientID] INT NULL,
PRIMARY KEY CLUSTERED ([receiptID] ASC)
);
Thanks alot and take care!

SOLVED
Apparently the "Did you try turning it on/off" method work sometimes...
I restarted my visual studio project and worked.

Related

SQL Server CE 4.0 database throws "No key matching the described characteristics could be found within the current range"

I'm a little stuck with an error that is a bit weird and I have never seen it until today. I have a primary key PK__SessionsLog__0000000000000082 and when I'm trying to remove with this command:
alter table sessionslog
drop constraint PK__SessionsLog__0000000000000082
I get this error:
No key matching the described characteristics could be found within the current range
With no other information provided.
Does someone have a clue what is happening?
Other technical information:
The SQL Server CE database version I'm using is 4.0
The primary key does exist; I can list it with the following command:
select CONSTRAINT_NAME
from INFORMATION_SCHEMA.KEY_COLUMN_USAGE
where table_name = 'sessionslog' and column_name = 'sessionid'
The sessionslog was created using this following query,
CREATE TABLE SessionsLog(
SessionID uniqueidentifier NOT NULL PRIMARY KEY,
ReportFile IMAGE NULL,
LogFile IMAGE NULL );
The table was in a database created on a Windows 8.1 O.S. I'm trying to do the drop on a Windows 7 due a migration.
If I try drop the table it says the same thing: "No key matching the described characteristics could be found within the current range".

Can't create graph tables with sqlproj

After getting really fed up with using hierarchyids to manage my node tree, I decided to take a stab at using SQL Server 2017's graph functionality to ease my troubles.
I have a little bit of confusion, though. Currently, all of my SQL scripts are stored and organized in a SQL database project. When I create a node table and publish it to my Azure SQL Database, it only creates a standard table.
However, I can paste the exact same query into SSMS and it creates the graph table just fine. I've included the query below. Am I missing anything obvious?
CREATE TABLE [dbo].[GraphSite]
(
[SiteId] UNIQUEIDENTIFIER NOT NULL DEFAULT NEWID(),
[SiteName] NVARCHAR(100) NOT NULL,
[SiteTypeId] UNIQUEIDENTIFIER NOT NULL,
[SiteTimeZone] NVARCHAR(20) NOT NULL DEFAULT N'America/New_York',
[SiteStatusId] UNIQUEIDENTIFIER NULL,
[SiteThemeId] UNIQUEIDENTIFIER NULL,
CONSTRAINT [PK_GraphSite] PRIMARY KEY ([SiteId]),
CONSTRAINT [FK_GraphSite_SiteType] FOREIGN KEY ([SiteTypeId]) REFERENCES [SiteType]([SiteTypeId]),
CONSTRAINT [FK_GraphSite_SiteStatus] FOREIGN KEY ([SiteStatusId]) REFERENCES [SiteStatus]([SiteStatusId]),
CONSTRAINT [FK_GraphSite_SiteTheme] FOREIGN KEY ([SiteThemeId]) REFERENCES [SiteTheme]([SiteThemeId])
) AS NODE;
EDIT: I installed SQL Server 2017 locally and it leaves "AS NODE;" in fine. So SSDT seems to have an issue building graph tables to Microsoft Azure SQL Database v12. Which is weird, considering Azure SQL databases fully support graph tables. Any thoughts?
Could you try downloading the latest version of SSDT from here: https://learn.microsoft.com/en-us/sql/ssdt/download-sql-server-data-tools-ssdt
This should fix the problem for you.

Jetbrains Datagrip 2017.1.3, force columns exported when dumping data to sql inserts file

I have an SQL server database with a lot of tables and data. I need to reproduce it locally in a docker container.
I have successfully exported the schema and reproduced it. When I dump data to an SQL file, it does not export automatically generated fields (Like ids or uuids for example)
Here is the schema for the user table:
create table user (
id_user bigint identity constraint PK_user primary key,
uuid uniqueidentifier default newsequentialid() not null,
id_salarie bigint constraint FK_user_salarie references salarie,
date_creation datetime,
login nvarchar(100)
)
When it exports and element from this table, I get this kind of insert:
INSERT INTO user(id_salarie, date_creation, login) VALUES (1, null, "example")
As a consequence, most of my inserts give me foreign key errors, because the ids generated by my new database are not the same as the ones in the old database. I can't change everything manually as there is way too much data.
Instead, I would like to have this kind of insert:
INSERT INTO user(id_user, uuid, id_salarie, date_creation, login) VALUES (1, 1, "manuallyentereduuid" null, "example")
Is there any way to do this with Datagrid directly? Or maybe a specific SQL server way of generating insert statements this way?
Don't hesitate to ask for more details in comments.
You need the option 'Skip generated columns' while configuring INSERT extractor.
It seems like Datagrip does not give you that possibility so I used something else : DBeaver. It is free and based on the Eclipse Environment.
The method is simple :
Select all the tables you want to export
Right click -> Export table data
From there you just have to follow the instructions. It outputs one file per table, which is a good thing if you have a consequent volumetry. I had trouble executing the whole script and had to split it when using Datagrip.
Hope this helps anyone encountering the same problem. If you find the solution directly in datagrip, I would like to know too.
EDIT : See the answer above

How to set a primary key using SQL

I have this table 'Cars', attributes:
MODEL nvarchar(20)
STYLE nvarchar(20)
ENGINE nvarchar(5)
CAPACITY smallint
MAX_SPEED smallint
PRICE smallmoney
MARKET nvarchar(20)
COMPETITOR nvarchar(20)
I would like to set 'PRICE' as the primary key via a SQL sStatement, so I've tried:
ALTER TABLE Cars
ADD PRIMARY KEY (PRICE)
But I just get the error
The ALTER TABLE SQL construct or statement is not supported.
in Visual Studio 2010.
As has been said above, price is a bad primary key. But ... the correct syntax to do what you are trying to do is:
ALTER TABLE Cars
ADD CONSTRAINT cars_pk PRIMARY KEY (PRICE)
Visual studio is not a database client. If you want to run any query at all, you have to use a client that allows you to do so. The details depend on the database engine you are using.
If you want to do this with Visual Studio, you have to send that command, as a query, the same way you would send a select query. Once again, the details depend on your database engine.
Something else that depends on the database engine is the syntax of the command itself. Some will allow what you tried. Other will make you use the constraint keyword.
Finally, as mentioned in the comments, price is a poor choice for the primary key. Better choices would be a uuid, an autoincrementing integer, or, the VIN.

How to alter SQL Table default data type during design

I would like to change the default data type when designing a table in SQL Server Management Studio Table Designer. My current default is nchar(10) and I am creating a table with a lot of integer data types. I looked in Tools Options but could not find anyplace to change this. I'm running SQL Server 2008 R2.
It is possible, but requires a modification of the registry.
This is a tiresome change to make every time you wish to change the default, so I agree with NYCdotNet.
HKEY_CURRENT_USER\Software\Microsoft\Microsoft SQL Server\100\Tools\Shell\DataProject
It sounds like you're ready to create your table using T-SQL and not the designer. A variation of the below code will cover you for putting together a basic schema and if you want to do more stuff you can always revise the table in the designer later.
CREATE TABLE MyTableName (
MyID INT NOT NULL IDENTITY(1,1),
MyColumn1 INT NOT NULL,
MyColumn2 INT NULL,
MyColumn3 VARCHAR(100) NULL,
PRIMARY KEY (MyID)
)
UPDATE: My apologies, read your question too fast. This solution is for the visual designer in VS2015, not SQLSMS. I will leave the answer up anyway.
This has been changed in Visual Studio 2015. It is now in:
Options > Database Tools > Table and Database Designers > Column Options