Withdata Software

Producing high-quality database tools

Main menu

Skip to primary content
Skip to secondary content
  • Withdata Software
  • Blog
  • Categories
  • Tags

Category Archives: Sql Server

Some ETL (Extract-Transform-Load) tools for SQL Server

Posted on August 11, 2017 by Shiji Pan

Withdata Software provide some ETL (Extract-Transform-Load) tools for SQL Server: FileToDB Load TXT, CSV, TSV, XML, JSON, Excel, SQL, RDF, INI data to SQL Server DBToFile Export SQL Server data to TXT, CSV, TSV, XML, JSON, Excel, SQL files DBCopier Copy data between SQL Server and ... Read more

Posted in Sql Server | Tagged ETL, Extract-Transform-Load, Sql Server

How to get index column names of a table from SQL Server

Posted on October 24, 2016 by Shiji Pan

select i.name as IndexName, co.[name] as ColumnName from sys.indexes i join sys.objects o on i.object_id = o.object_id join sys.schemas s on s.schema_id = o.schema_id join sys.index_columns ic on ic.object_id = i.object_id and ic.index_id = i.index_id join sys.columns co on co.object_id = ... Read more

Posted in Sql Server | Tagged get index columns, Sql Server

How to get primary key of a table from SQL Server

Posted on October 24, 2016 by Shiji Pan

SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE OBJECTPROPERTY(OBJECT_ID(CONSTRAINT_SCHEMA + '.' + CONSTRAINT_NAME), 'IsPrimaryKey') = 1 AND TABLE_NAME = 'my_table_name' AND TABLE_SCHEMA = 'my_schema_name' See also: How to get primary key of a table from PostgreSQL How to get ... Read more

Posted in Sql Server | Tagged get primary key, Sql Server

How to execute sql file at SQL Server command line

Posted on August 29, 2013 by Shiji Pan

You can use sqlcmd to run a Transact-SQL script file. A Transact-SQL script file is a text file that can contain a combination of Transact-SQL statements, sqlcmdcommands, and scripting variables. To run the script file 1.Open a command prompt window. 2.In the Command Prompt window, ... Read more

Posted in Sql Server | Tagged command line, command line execute sql, Sql Server

How to create a user in SQL Server Express database

Posted on July 23, 2013 by Shiji Pan

Create a SQL Authenticated login first with CREATE LOGIN, then add a user associated with that login to your database by using CREATE USER. USE [master] GO CREATE LOGIN [YourUsername] WITH PASSWORD=N'YourPassword', DEFAULT_DATABASE=[YourDB], CHECK_EXPIRATION=OFF, ... Read more

Posted in Sql Server | Tagged create user in SQL Server Express, Sql Server, SQL Server Express

The SQL Server equivalent for the MySQL Limit

Posted on June 25, 2013 by Shiji Pan

In MySQL, you can use “Limit n,m”, like this: select * from sometable order by name limit 20,10 And in SQL Server, use this query: SELECT * FROM ( SELECT *, ROW_NUMBER() OVER (ORDER BY name) as rowNum FROM sometable ) sub WHERE rowNum > 20 AND ... Read more

Posted in Sql Server | Tagged equivalent for the MySQL Limit, Sql Server

How to generate a CREATE TABLE statement for a given table in SQL Server

Posted on June 12, 2013 by Shiji Pan

declare @table varchar(100) set @table = 'my_table' -- set table name here declare @sql table(s varchar(1000), id int identity) -- create statement insert into @sql(s) values ('create table [' + @table + '] (') -- column list insert into @sql(s) select ' ['+column_name+'] ' + ... Read more

Posted in Sql Server | Tagged generate a CREATE TABLE statement, Sql Server

Replace (Update/Insert) a row into SQL Server table

Posted on June 4, 2013 by Shiji Pan

In MySQL,  we use “ON DUPLICATE KEY UPDATE” to either updates or inserts a row in a table. How to do it in SQL Server? Just like this: if not exists (select 1 from employees where employee_id = 1) insert into employees (employee_id,last_name,first_name) values ( 1,'smith', ... Read more

Posted in Sql Server | Tagged merge into, replace into, Sql Server, upsert

Remove duplicate rows in SQL Server

Posted on May 31, 2013 by Shiji Pan

Assuming no nulls, you GROUP BY the unique columns (eg. col_1, col_2, col_3), and SELECT the MIN (or MAX) Row ID (eg. row_id) as the row to keep. Then, delete everything that didn’t have a row id: DELETE my_table FROM my_table LEFT OUTER JOIN ( SELECT MIN(row_id) as row_id, col_1, ... Read more

Posted in Sql Server | Tagged Remove duplicate rows, Sql Server

How to get column names from Sql Server table

Posted on May 30, 2013 by Shiji Pan

SELECT [name] AS [Column Name] FROM syscolumns WHERE id = (SELECT id FROM sysobjects WHERE type = ‘U’ AND [Name] = ‘My_Table_Name’) Type = ‘V’ for views Type = ‘U’ for tables For SQL Server 2008, we can use information_schema.columns for getting ... Read more

Posted in Sql Server | Tagged get column names, Sql Server

Recent Posts

  • Use Cases for Dumping to CSV
  • Convert Text to Speech by CSV / TSV
Withdata Software. ©2004 - 2025 All rights reserved.