You are here: Home >Posts Tagged ‘SQL Query

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

SQL SERVER – Attach mdf file without ldf file in Database

Background Story: One of my friends recently called up and asked me if I had spare time to look at his database and give him a performance tuning advice. Because I had some free time to help him out, I said yes. I asked him to send me the details of his database structure and [...]

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

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

SQL NOT NULL Constraint

คำสั่ง SQL NOT NULL constraint เป็นคำสั่งที่ใช้สำหรับจำกัดค่าในคอลัมน์นั้นห้ามเป็นค่าว่าง หากมีการเพิ่มข้อมูลแล้วคอลัมน์ดังกล่าวว่างหรือไม่มีข้อมูลก็จะไม่สามารถเพิ่มหรือแก้ไขให้เป็นว่างได้ The NOT NULL constraint enforces a column to NOT accept NULL values. The NOT NULL constraint enforces a field to always contain a value. This means that you cannot insert a new record, or update a record without adding a value to this field. The following SQL enforces [...]

Tags: , , , ,

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

SQL SELECT INTO Statement

คำสั่ง SQL SELECT INTO เป็นคำสั่งสำหรับทำการ Backup หรือ Copies Table ซึ่งการใช้คำสั่งนี้จะสร้างตารางให้โดยอัติโนมัต โดยที่ไม่ต้องมี Table อยู่ก่อน The SQL SELECT INTO statement can be used to create backup copies of tables.

Tags: , , , , ,

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

SQL UNION & UNION ALL Operator

คำสั่ง UNION & UNION ALL ต่างก็เป็นคำสั่งสำหรับการเอาข้อมูลมาต่อกัน ซึ่งก็มีความแตกต่างกันพอสมควร ประสิทธิภาพของการทำงานของคำสั่ง UNION & UNION ALL ก็ต่างกัน The SQL UNION operator combines two or more SELECT statements. The SQL UNION Operator คำสั่ง SQL UNION เป็นคำสั่งที่เอาตารางข้อมูลตั้งแต่สองตารางมาต่อกัน ซึ่งหากสองตารางมี Rows ข้อมูลที่เหมือนกันจะเอามาแค่ Rows เดียว คำสั่ง SQL UNION ALL เป็นคำสั่งที่เอาตารางข้อมูลตั้งแต่สองตารางมาต่อกันโดยจะไม่สนใจข้อมูลภายในตารางแต่เป็นการเอาข้อมูลในตารางมาต่อกันเลย ข้อควรระวัง Table ที่นำมาทำการ UNION หรือ UNION ALL จะต้องมี Column ตรงกันด้วยครับ The UNION operator is [...]

Tags: , , , , , , , , ,

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

SQL FULL JOIN Keyword

คำสั่ง SQL FULL JOIN จะแสดงทุก Record ของทั้ง 2 ตารางไม่ว่า Record จะ Match Join Condition หรือไม่ก็ตาม The FULL JOIN keyword return rows when there is a match in one of the tables.

Tags: , , , ,

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

SQL INNER JOIN Keyword

คำสั่ง SQL INNER JOIN Keyword เป็นคำสั่งสำหรับเชื่อมข้อมูลตั้งแต่สองตารามขึ้นไป โดยค่าที่ Return จะเป็นค่าที่ตั้งแต่สองตารางตรงกันเท่านั้น The INNER JOIN keyword return rows when there is at least one match in both tables.

Tags: , , , , , ,

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

SQL Joins

SQL Joins เป็นคำสั่งสำหรับเชื่อมข้อมูลที่มีตั้งแต่สองตารางขึ้นไป โดยมีความสัมพันธ์ระหว่างบางคอลัมน์ที่มีดาต้าเหมือนกัน หรือเป็นการเชื่อมระหว่าง Primary key กับ Foreign Key ซึ่งค่าที่เป็น Primary key จะต้องเป็นค่าที่ไม่ซ้ำ ข้อพึงระวัง SQL Joins จะเป็นคำสั่งที่เปลืองประสิทธิภาพเครื่องมากหากข้อมูลที่นำมาก Joins กันมาขนาดใหญ่ SQL joins are used to query data from two or more tables, based on a relationship between certain columns in these tables.

Tags: , , , , , , , ,

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