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

No version of SQL Server has this. It would be useful (PostreSQL has the same and I like it). In SQL Server, there are table types (CREATE TYPE), temporary tables (CREATE TABLE #foo) and table variables (DECLARE @var TABLE), but you can't mimic or inherit a table definition using %TYPE or CREATE TABLE .. INHERITS/OF


3

From the documentation: createdb is a wrapper around the SQL command CREATE DATABASE. There is no effective difference between creating databases via this utility and via other methods for accessing the server. This means that you can write a script which issues a command like psql -f createdb.sql -v passwd=$passwd -v user=$user Where ...


3

Using a batch file and SQLCMD, you can execute the script as below : cls echo off set DbServer=Server_name\InstanceName set MyLogin=sa set MyPassword=StrongPassword set MasterDbName=master set DbName=AdventureWorks set SQLCMDPath=C:\Program Files\Microsoft SQL Server\90\Tools\binn set SpScripFilePath=C:\ScriptFolder set SpScripFileName=test.sql echo ...


3

As you describe it, it's not going to work. The T-SQL script needs to run on a SQL Server which means that it needs to be run in an appropriately-authenticated session. One option would be to write the TSQL script, and then provide it with a VBScript or CMD file or PowerShell script that'll launch the TSQL at the correct server with the right credentials.


2

You can use pg_basebackup to take a copy of the PostgreSQL database over the replication protocol. It copies the whole DB though, it isn't incremental. You'll want to use the --xlog-method=stream argument unless you have a shared WAL archive set up. Streaming replication isn't really well suited to the purpose you describe. You can set it to have ...


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

The tablespace content type (Datatype in your second example) is defined in sqlutil.h: /* table space contents */ #define SQLB_TBS_ANY 0x0 /* All permanent data. Regular table */ /* space. */ #define SQLB_TBS_LARGE 0x20 ...


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


2

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 ...


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

What you're referring to is usually called Test Data Management. There are several commercial solutions, e.g. IBM Optim Test Data Management (disclosure: I work for IBM, but don't speak for them). I'm not aware of any free products that can perform that function, so I'm afraid you'll have to stick to your Python scripts unless you have deep pockets. On a ...


1

In order to connect to your PostgreSQL instance and run the createdb script, which is a client, you can use a password file. This file is generally located at ~/.pgpass and must contain theses information : hostname:port:database:username:password If you want to use a different path for your password file, you can set the PGPASSFILE environment variable. ...



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