Tag Info

Hot answers tagged

5

If I understand correctly, you want to restart the numbering with 0 for every table. Use the window function row_number() in an UPDATE: UPDATE tbl t SET xid = n.xid FROM (SELECT ctid, row_number() OVER(ORDER BY aid,bid,cid) - 1 AS xid FROM tbl) n WHERE t.ctid = n.ctid; Using ctid as poor man's surrogate for a primary key, since you neglected to ...


3

I would personally just do a backup for each database, and then attach them to the new server. Just remember to use EXEC sp_change_users_login 'Auto_Fix', 'username' for fixing user accounts. The Wizard approach sounds doable. I you need another approach for scripting DDL, the scptxfr.exe tool that comes with earlier version of SQL Server still works with ...


3

Redis doesn't do scheduling of jobs/scripts - you'll have to use something (e.g. cron) to trigger the script. The script itself sounds simple enough - LRANGE should be used to iterate the list's elements, sum them up, SET total-count to the result and DEL the list. Lua would be perfect for this but you can also .sh with redis-cli for example. What bothers ...


2

You can use below script : SELECT QUOTENAME(SCHEMA_NAME(tb.[schema_id])) AS 'SchemaName' ,QUOTENAME(OBJECT_NAME(tb.[OBJECT_ID])) AS 'TableName' ,C.NAME AS 'ColumnName' ,T.NAME AS 'DataType' ,C.max_length ,C.is_nullable FROM SYS.COLUMNS C INNER JOIN SYS.TABLES tb ON tb.[object_id] = C.[object_id] INNER JOIN SYS.TYPES T ON C.system_type_id ...


2

If you click on the 'Script' in the execute box that pops up from the delete button, it reveals that the script actually uses a DROP command: USE [DATABASE] GO /****** Object: Table [dbo].[TABLE] Script Date: 3/6/2014 9:29:39 AM ******/ DROP TABLE [dbo].[TABLE] GO


1

/****** Object: Database [DatabaseName] Script Date: 03/06/2014 10:32:06 AM ******/ DROP DATABASE [DatabaseName] GO However, you should probably just use the RESTORE DATABASE command and use the REPLACE option. REPLACE Specifies that SQL Server should create the specified database and its related files even if another database already exists with ...


1

Let's say the new default you want is 5: DECLARE @sql NVARCHAR(MAX) = N''; SELECT @sql += N'ALTER TABLE ' + t + ' DROP CONSTRAINT ' + c + '; ALTER TABLE ' + t + ' ADD CONSTRAINT ' + c + ' DEFAULT (5) FOR [project_id];' FROM ( SELECT t = QUOTENAME(s.name) + '.' + QUOTENAME(t.name), c = QUOTENAME(d.name) FROM sys.tables AS t INNER JOIN ...



Only top voted, non community-wiki answers of a minimum length are eligible