sql-server

“Specified type is not registered” error when bulk inserting table with geospatial data types

与世无争的帅哥 提交于 2021-02-20 17:56:41
问题 I'm trying to use the SqlBulkCopy class from the System.Data assembly (4.6.1) to bulk insert a table with a geospatial data type, using code that looks roughly like this (adapted from https://github.com/MikaelEliasson/EntityFramework.Utilities): public void InsertItems<T>(IEnumerable<T> items, string schema, string tableName, IList<ColumnMapping> properties, DbConnection storeConnection, int? batchSize) { using (var reader = new EFDataReader<T>(items, properties)) { var con = (SqlConnection

“Specified type is not registered” error when bulk inserting table with geospatial data types

*爱你&永不变心* 提交于 2021-02-20 17:56:04
问题 I'm trying to use the SqlBulkCopy class from the System.Data assembly (4.6.1) to bulk insert a table with a geospatial data type, using code that looks roughly like this (adapted from https://github.com/MikaelEliasson/EntityFramework.Utilities): public void InsertItems<T>(IEnumerable<T> items, string schema, string tableName, IList<ColumnMapping> properties, DbConnection storeConnection, int? batchSize) { using (var reader = new EFDataReader<T>(items, properties)) { var con = (SqlConnection

Create database if db not exist

不羁的心 提交于 2021-02-20 08:33:27
问题 I want to make SQL Server scritp for creating database if not exist. IF NOT EXISTS(SELECT * FROM sys.databases WHERE name = 'DataBase') BEGIN CREATE DATABASE DataBase USE DataBase CREATE TABLE TableName ( Id INT PRIMARY KEY IDENTITY (1, 1), Name VARCHAR(100) ) --more tables here --some procedures here too END From code above i getting this error: Msg 911, Level 16, State 1, Line 5 Database 'DataBase' does not exist. Make sure that the name is entered correctly. How to make database with

Create database if db not exist

老子叫甜甜 提交于 2021-02-20 08:31:49
问题 I want to make SQL Server scritp for creating database if not exist. IF NOT EXISTS(SELECT * FROM sys.databases WHERE name = 'DataBase') BEGIN CREATE DATABASE DataBase USE DataBase CREATE TABLE TableName ( Id INT PRIMARY KEY IDENTITY (1, 1), Name VARCHAR(100) ) --more tables here --some procedures here too END From code above i getting this error: Msg 911, Level 16, State 1, Line 5 Database 'DataBase' does not exist. Make sure that the name is entered correctly. How to make database with

Certificate-Based Authentication in SQL Server

允我心安 提交于 2021-02-20 05:21:06
问题 currently i'm struggling with my current project. I was tasked to replace the use of Username/Password based Authentication/Connection to SQL Server (2014) and replace it with a Certificate based Authentication/Connection one. So probably my questions are: Is this possible with SQL Server ? The idea is to no longer include the username/password combination to connect to the Database Instance from the Server. This then would be replaced by a certificate where, ideally would hold all the login

TSQL Dynamic Update of TOP(n) Rows

会有一股神秘感。 提交于 2021-02-20 05:18:49
问题 i have a table with one line per travel second table has values of origin and destination and quantity for each combination i need to run an update that run on the second table that update top N rows on the first table (n comes from the second table) im using this update script inside a cursor in a procedure : ALTER PROCEDURE [dbo].[SP_Travels_History_FromMissing] AS BEGIN SET NOCOUNT ON; DECLARE @C_Day_Type_Code INT = NULL DECLARE @C_PartOfDay_Code INT = NULL DECLARE @C_Station_From INT =

How to add 2 foreign keys in a table in a SQL Server?

时光总嘲笑我的痴心妄想 提交于 2021-02-20 04:57:59
问题 I have 2 tables, one of them has 2 foreign keys and another has 2 composite foreign keys in it. Whenever I try to run the query, it says error and could not create constraint or index. So I have two tables here. I know I'm completely wrong, I apologize for that as I'm kind of new to coding. create table Booking ( BookingID char(4) primary key, dateBooked datetime not null, creditCard char(16) null, expiryDate datetime not null, CVC char (3) not null, confirmationID char(4) not null,

SQL BCP with column name

天涯浪子 提交于 2021-02-20 04:44:07
问题 I am trying to export my stored procedure to a .csv file using BCP. It does give me a output file in .CSV but it does not print column name. Below is the script. Please look at and let me know what i am missing DECLARE @command VARCHAR(4000) declare @fulldate varchar(30) = convert(varchar,GETDATE(),112) declare @year varchar(30) = left(@fulldate,4) declare @day varchar(30) = right(@fulldate,2) declare @month varchar(30) = left(right(@fulldate,4),2) DECLARE @FileDirectory VARCHAR(1000) = 'c:\'

Convert decimal <--> binary with T-SQL

梦想的初衷 提交于 2021-02-20 03:51:16
问题 How can I convert binary (base 2 stored as varchar) into decimal (base 10 stored as int or bigint) and the other way around, using T-SQL? Example results: 7 (dec) <--> 111 (bin) 136 (dec) <--> 10001000 (bin) 2123942362 (dec) <--> 1111110100110001100100111011010 (bin) 回答1: This answer can handle bigint Convert to bit(varchar containing 1 and 0) DECLARE @input BIGINT = 9223372036854775807 ;WITH N(N)AS ( SELECT top 63 POWER(cast(2 as bigint), ROW_NUMBER()over(ORDER BY (SELECT 1))-1) FROM (VALUES

Convert decimal <--> binary with T-SQL

时间秒杀一切 提交于 2021-02-20 03:49:30
问题 How can I convert binary (base 2 stored as varchar) into decimal (base 10 stored as int or bigint) and the other way around, using T-SQL? Example results: 7 (dec) <--> 111 (bin) 136 (dec) <--> 10001000 (bin) 2123942362 (dec) <--> 1111110100110001100100111011010 (bin) 回答1: This answer can handle bigint Convert to bit(varchar containing 1 and 0) DECLARE @input BIGINT = 9223372036854775807 ;WITH N(N)AS ( SELECT top 63 POWER(cast(2 as bigint), ROW_NUMBER()over(ORDER BY (SELECT 1))-1) FROM (VALUES