You are here: Home >Archive for the ‘Database Tutorials’ Category

SQL SERVER – How to Rename a Column Name or Table Name

I often get request from blog reader for T-SQL script to rename database table column name or rename table itself. The script for renaming any column : sp_RENAME ‘TableName.[OldColumnName]‘ , ‘[NewColumnName]‘, ‘COLUMN’ The script for renaming any object (table, sp etc) : sp_RENAME ‘[OldTableName]‘ , ‘[NewTableName]‘ This article demonstrates two examples of renaming database object. [...]

Tags: , , , , , , , , ,

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • Twitter
  • RSS

MySQL grant user permissions

Table of contents : What is MySQL grant? How to GRANT privileges to users Resources What is MySQL grant The MySQL database software offers both administrators and users a great amount of control options. You can learn more about the users’ MySQL management rights in our articles dedicated to the create-user, create-database, create-table and alter-table [...]

Tags: , ,

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • Twitter
  • RSS

SQL Server DATEDIFF() Function

Definition and Usage The DATEDIFF() function returns the time between two dates. Syntax DATEDIFF(datepart,startdate,enddate) Where startdate and enddate are valid date expressions and datepart can be one of the following: datepart Abbreviation year yy, yyyy quarter qq, q month mm, m dayofyear dy, y day dd, d week wk, ww weekday dw, w hour hh [...]

Tags: , ,

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • Twitter
  • RSS

ALTER TABLE Statement

The ALTER TABLE statement allows you to rename an existing table. It can also be used to add, modify, or drop a column from an existing table.   Renaming a table The basic syntax for renaming a table is: ALTER TABLE table_name RENAME TO new_table_name; For example: ALTER TABLE suppliers RENAME TO vendors; This will [...]

Tags: , , , , , ,

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • Twitter
  • RSS

SQL SERVER – How to Rename a Column Name or Table Name

I often get request from blog reader for T-SQL script to rename database table column name or rename table itself. The script for renaming any column : sp_RENAME ‘TableName.[OldColumnName]‘ , ‘[NewColumnName]‘, ‘COLUMN’ The script for renaming any object (table, sp etc) : sp_RENAME ‘[OldTableName]‘ , ‘[NewTableName]‘ This article demonstrates two examples of renaming database object. [...]

Tags: , , , , , , , , , , ,

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • Twitter
  • RSS

SQL SERVER – Import CSV File Into SQL Server Using Bulk Insert – Load Comma Delimited File Into SQL Server

bulk insert csv sql server Server: Msg 4861, Level 16, State 1, Line 1 This is very common request recently – How to import CSV file into SQL Server? How to load CSV file into SQL Server Database Table? How to load comma delimited file into SQL Server? Let us see the solution in quick [...]

Tags: , , , , , , , , , , ,

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • Twitter
  • RSS

How to Alter a Replicated Article in SQL Server 2005

Introduction One of the fairly frequently asked questions on the Microsoft replication discussion boards concerns how to alter a replicated article. For simple cases this is quite straightforward – adding a column is achieved using sp_repladdcolumn, while sp_repldropcolumn is used to drop a column. However, what if we want to change an existing column – [...]

Tags: , ,

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • Twitter
  • RSS

Altering a column on a Replicated Table

Sometimes the schema of a replicated table needs altering. There are many reasons this might be the case eg possibly the datatype has been incorrectly chosen, or a default is missing, or we want to rename a column. Attempting to change the table schema directly will result in the error “Cannot alter/drop the table ‘tablename’ [...]

Tags:

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • Twitter
  • RSS

SQL Server – Creating and using Dump Devices for Backups

A dump device is simply a logical device which redirects to a specified physical device. The main advantage of using a dump device for backups is it reduces the change required to backup code. For example, if you are backing up to a Network location. If you have hard-coded the backup location then the network [...]

Tags: , , ,

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • Twitter
  • RSS

SQL Server – Row count for all views / tables

Getting row count for all tables in a database is straight forward. You can display row count for all tables by joining sys.objects and sys.partitions as below: USE   [AdventureWorks2008R2] GO   SELECT      SCHEMA_NAME(A.schema_id) + ‘.’ + A.Name, SUM(B.rows) AS ‘RowCount’ FROM        sys.objects A INNER JOIN sys.partitions B ON A.object_id = B.object_id WHERE       A.type [...]

Tags: , ,

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • Twitter
  • RSS