Skip to content

Instantly share code, notes, and snippets.

View arekgotfryd's full-sized avatar
👽
Working from home

Arkadiusz arekgotfryd

👽
Working from home
View GitHub Profile
@arekgotfryd
arekgotfryd / gist:8d01135f44882b93677b9a83a010dbbb
Created February 8, 2019 08:44
sql-server-add-auto-increment-primary-key-to-existing-table
ALTER TABLE dbo.YourTable
ADD ID INT IDENTITY
CONSTRAINT PK_YourTable PRIMARY KEY CLUSTERED
@arekgotfryd
arekgotfryd / gist:4bf2566f430fa42ed20d7b1e1f31c964
Created November 28, 2018 13:05
TITLE: Microsoft SQL Server Management Studio Cannot execute script. ADDITIONAL INFORMATION: Insufficient memory to continue the execution of the program. (mscorlib)
Use sqlcmd tool just like below:
SQLCMD -S TestSQLServer\SQLEXPRESS -U sa -P sasa -d AdventureWorks2018 -i "d:\document\sql document\script.sql"
1. Create table with PRIMARY_KEY
CREATE TABLE dbo.AuditLog
(
AuditLogID int constraint PK_AuditLog_AuditLogID primary key
)
2. Create table with unique clustered
CREATE UNIQUE CLUSTERED INDEX PK_AuditLog_AuditLogID
ON dbo.AuditLog(AuditLogID)
SELECT [SUBURB]
,[COLUMN_TYPE]
,[HEIGHT]
,[COLUMN_MATERIAL]
,[OUTREACH_ARM_LENGTH]
,[LUMINAIRE]
,[LAMP_TYPE]
,[LAMP_COUNT]
,[LAT]
,[LON]
BULK INSERT dbo.output
FROM 'F:\Temp\Prezka\transformData\output2.csv'
WITH
(
FIRSTROW = 2,
FIELDTERMINATOR = ',', --CSV field delimiter
ROWTERMINATOR = '0x0a', -- \n
ERRORFILE = 'F:\Temp\Prezka\transformData\errors.csv',
TABLOCK
)
UPDATE online_bookstore.book SET unit_price = TRUNCATE(RAND()*(10-5)+5,2);
UPDATE [YOUR_TABLE] SET [POINT_GEOM] = geometry::STPointFromText('POINT(' + CAST([X] AS VARCHAR(20)) + ' ' + CAST([Y] AS VARCHAR(20)) + ')', 4326);
var mongoose = require(mongoose),
User = require(./user-model);
var connStr = mongodb://localhost:27017/mongoose-bcrypt-test;
mongoose.connect(connStr, function(err) {
if (err) throw err;
console.log(Successfully connected to MongoDB);
});
// create a user a new user
var mongoose = require("mongoose");
var bcrypt = require("bcrypt");
var Schema = mongoose.Schema;
const SALT_WORK_FACTOR = 10;
var UserSchema = new Schema({
email: { type: String, required: true, index: { unique: true } },
password: { type: String, required: true }
});
UserSchema.pre("save", function(next) {
var user = this;
// only hash the password if it has been modified (or is new)
if (!user.isModified("password")) return next();
// generate a salt
bcrypt.genSalt(SALT_WORK_FACTOR, function(err, salt) {
if (err) return next(err);
// hash the password using our new salt
bcrypt.hash(user.password, salt, function(err, hash) {