sql-server-2016

Entity Framework not working with temporal table

…衆ロ難τιáo~ 提交于 2019-11-27 14:44:11
I'm using database first entity framework 6. After changing some of the tables in my schema to be temporal tables, I started getting the following error when attempting to insert new data: Cannot insert an explicit value into a GENERATED ALWAYS column in table '<MyDatabase>.dbo.<MyTableName>. Use INSERT with a column list to exclude the GENERATED ALWAYS column, or insert a DEFAULT into GENERATED ALWAYS column. It looks like EF is trying to update the values of the PERIOD columns which are managed by the system. Removing the columns from the EDMX file seems to correct the problem, but this is

Always encrypted Behavior in SQL Server 2016

空扰寡人 提交于 2019-11-27 09:21:55
I was doing some demo in SQL Server 2016 for topic Always encrypted. Got few doubts. Below are the steps followed: In Database server (hosted in Microsoft Azure VM): In table MyTable , Created the Column Encryption Key (CEK) and Master Encryption Key (CMK) Select * from MyTable , shows encrypted data.(both from App and DB server) Exported the certificate from Database Server Imported the certificate in App Server (my Local machine) Added Column Encryption Setting=Enabled to the connection string of my application. It is working fine, now it shows the plain text data as expected. Doubt: In

How do I move a table into a schema in T-SQL

删除回忆录丶 提交于 2019-11-27 06:05:38
I want to move a table into a specific Schema using T-SQL? I am using SQL Server 2008. Mitch Wheat ALTER SCHEMA TargetSchema TRANSFER SourceSchema.TableName; If you want to move all tables into a new schema, you can use the undocumented (and to be deprecated at some point, but unlikely!) sp_MSforeachtable stored procedure: exec sp_MSforeachtable "ALTER SCHEMA TargetSchema TRANSFER ?" Ref.: ALTER SCHEMA SQL 2008: How do I change db schema to dbo Short answer: ALTER SCHEMA new_schema TRANSFER old_schema.table_name I can confirm that the data in the table remains intact, which is probably quite

SQL Server OPENJSON read nested json

廉价感情. 提交于 2019-11-27 05:08:48
问题 I have some json that I would like to parse in SQL Server 2016. There is a hierarchy structure of Projects->Structures->Properties. I would like to write a query that parses the whole hierarchy but I don't want to specify any elements by index number ie I don't want to do anything like this: openjson (@json, '$[0]') or openjson (@json, '$.structures[0]') I had this idea that I could read the values of the top level project objects along with the json string that represents the structures

FOR JSON path returns less number of Rows on AZURE SQL

谁说我不能喝 提交于 2019-11-27 04:51:16
问题 I am using AZURE SQL (SQL Server 2016) and creating a query to give me output in JSON object. I am adding FOR JSON PATH at the end of query. When I execute the procedure without adding FOR JSON PATH to the query, I get 244 rows (no of records in my table); but when I execute the procedure by adding FOR JSON PATH I get message 33 rows and also I get JSON object which is truncated. I tested this with different types of queries including simple query selecting only 10 columns, but I always get

Entity Framework not working with temporal table

房东的猫 提交于 2019-11-27 04:05:33
问题 I'm using database first entity framework 6. After changing some of the tables in my schema to be temporal tables, I started getting the following error when attempting to insert new data: Cannot insert an explicit value into a GENERATED ALWAYS column in table '<MyDatabase>.dbo.<MyTableName>. Use INSERT with a column list to exclude the GENERATED ALWAYS column, or insert a DEFAULT into GENERATED ALWAYS column. It looks like EF is trying to update the values of the PERIOD columns which are

Cannot be opened because it is version 852. this server supports version 782 and earlier

不羁的心 提交于 2019-11-27 03:23:17
问题 I am using Visual Studio 2017 and SQL Server 2014. While attaching a database file to Visual Studio, I get this error: "" After upgrading the file I used this connection string <connectionStrings> <add name="con" connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\binaaelmamorra.mdf;Integrated Security=True;Connect Timeout=30"/> </connectionStrings> It's working fine on my machine, but on the client machine, an error pops up saying Cannot be opened because it

SQL Server : can you limit access to only one table

旧街凉风 提交于 2019-11-27 01:51:28
问题 I think the answer is no but I'm looking to give someone access to a SQL Server database but I only really want them to have access to one table. It's easy enough to limit someone to only access one database but have no idea if I can limit to a single table. My thoughts were to create another database with a synonym to the other table and then limit the access to that database but I wondered if someone could think of a better way. I'm also not convinced that it will work as I think there will

how to Convert Table to Json Arrays?

杀马特。学长 韩版系。学妹 提交于 2019-11-26 21:38:28
问题 I'm using Sql Server 2016 and I want to convert a table to json. I have a simple Table : CREATE TABLE [dbo].[TableTmp]( [Color] [nvarchar](50) NULL, [Type] [nvarchar](50) NULL, [Number] [nvarchar](50) NULL ) ON [PRIMARY] GO INSERT [dbo].[TableTmp] ([Color], [Type], [Number]) VALUES (N'Blue', N'A', N'1') GO INSERT [dbo].[TableTmp] ([Color], [Type], [Number]) VALUES (N'Blue', N'A', N'2') GO INSERT [dbo].[TableTmp] ([Color], [Type], [Number]) VALUES (N'Blue', N'A', N'3') GO INSERT [dbo].

SQL Server: Filter output of sp_who2

浪尽此生 提交于 2019-11-26 18:43:41
问题 Under SQL Server, is there an easy way to filter the output of sp_who2? Say I wanted to just show rows for a certain database, for example. 回答1: You could try something like DECLARE @Table TABLE( SPID INT, Status VARCHAR(MAX), LOGIN VARCHAR(MAX), HostName VARCHAR(MAX), BlkBy VARCHAR(MAX), DBName VARCHAR(MAX), Command VARCHAR(MAX), CPUTime INT, DiskIO INT, LastBatch VARCHAR(MAX), ProgramName VARCHAR(MAX), SPID_1 INT, REQUESTID INT ) INSERT INTO @Table EXEC sp_who2 SELECT * FROM @Table WHERE ..