SQL Server DBA FAQs and Tips

SQL Server FAQs - Downloading and Installing SQL Server 2005 Express Edition

A collection of 14 FAQs on SQL Server 2005 Express Edition download and installation. Clear answers are provided with tutorial exercises on installing SQL Server 2005 Express Edition; installing .NET Framework Version 2.0; installing Management Studio Express Edition and Books Online.

  1. What is Microsoft SQL Server?
  2. How to download Microsoft SQL Server 2005 Express Edition?
  3. What are the requirements to install SQL Server 2005 Express Edition?
  4. Why I am getting "The Microsoft .Net Framework 2.0 in not installed" message?
  5. How to download and install Microsoft .NET Framework Version 2.0?
  6. What is mscorsvw.exe - Process - Microsoft .NET Framework NGEN?
  7. How to install SQL Server 2005 Express Edition?
  8. How do you know if SQL Server is running on your local system?
  9. What is sqlservr.exe - Process - SQL Server (SQLEX?PRESS)
  10. How to download and install Microsoft SQL Server Management Studio Express?
  11. How to connect SQL Server Management Studio Express to SQL Server 2005 Express?
  12. How to run Queries with SQL Server Management Studio Express?
  13. How to download and install SQL Server 2005 Books Online?
  14. How to run SQL Server 2005 Books Online on your local system?

More...

SQL Server Tutorials - Getting Started with Transact-SQL Statements

A collection of 10 tutorials for you to get started quickly with running Transact-SQL statements on SQL Server 2005. Clear examples are provided for running CREATE TABLE, INSERT, UPDATE, DELTE, SELECT, CREATE USER, GRANT EXECUTE statements.

  1. How to use Transact-SQL statements to access the database engine?
  2. How to create new databases with "CREATE DATABASE" statements?
  3. How to create new table with "CREATE TABLE" statements?
  4. How to insert and update data into a table with "INSERT" and "UPDATE" statements?
  5. How to read data in a table with "SELECT" statements?
  6. How to create a login to access the database engine using "CREATE LOGIN" statements?
  7. How to create a user to access a database using "CREATE USER" statements?
  8. How to create a view and a stored procedure using "CREATE VIEW/PROCEDURE" statements?
  9. How to grant a permission using "GRANT EXECUTE" statements?
  10. How to delete database objects with "DROP" statements?

More...

SQL Server FAQs - Creating and Managing Databases and Physical Files

A collection of 16 FAQs on creating and managing databases on SQL Server 2005. Clear answers are provided with tutorial exercises on creating, renaming, and deleting databases; setting current database; bringing databases offline and online; reviewing, moving and copy database physical files.

  1. What is a database?
  2. What is the simplest way to create a new database?
  3. How to set the current database?
  4. How to delete a database?
  5. Why I am getting this error when dropping a database?
  6. How to get a list all databases on the SQL server?
  7. Where is my database stored on the hard disk?
  8. How to create database with physical files specified?
  9. How to rename databases?
  10. Why I am getting this error when renaming a database?
  11. What are database states?
  12. How to set a database state to OFFLINE?
  13. How to move database physical files?
  14. How to set database to be READ_ONLY?
  15. How to set database to be SINGLE_USER?
  16. What are system databases?

More...

SQL Server FAQs - Creating/Managing Tables and Adding/Altering/Deleting Columns

A collection of 16 FAQs on creating and managing tables on SQL Server 2005. Clear answers are provided with tutorial exercises on creating, renaming, and deleting tables; reviewing, renaming, deleting and adding table columns; changing column data types.

  1. What is a table?
  2. What are DDL (Data Definition Language) statements for tables?
  3. How to create new tables with "CREATE TABLE" statements?
  4. How To Get a List of All Tables with "sys.tables" View?
  5. How To Get a List of Columns using the "sys.columns" View?
  6. How To Get a List of Columns using the "sp_columns" Stored Procedure?
  7. How To Get a List of Columns using the "sp_help" Stored Procedure?
  8. How To Generate CREATE TABLE Script on an Existing Table?
  9. How to create new tables with "SELECT ... INTO" statements?
  10. How To Add a New Column to an Existing Table with "ALTER TABLE ... ADD"?
  11. How To Delete an Existing Column in a Table with "ALTER TABLE ... DROP COLUMN"?
  12. How to rename an existing column with the "sp_rename" stored procedure?
  13. How to rename an existing column with SQL Server Management Studio?
  14. How to change the data type of an existing column with "ALTER TABLE" statements?
  15. How to rename an existing table with the "sp_rename" stored procedure?
  16. How To Drop an Existing Table with "DROP TABLE" Statements?

More...

SQL Server FAQs - Understanding INSERT, UPDATE and DELETE Statements

A collection of 18 FAQs on SQL INSERT, UPDATE and DELETE statements. Clear answers are provided with tutorial exercises on inserting, updating and deleting single and multiple rows; using column default values; using subqueries to INSERT and UPDATE statements.

  1. What Are DML (Data Manipulation Language) Statements?
  2. How To Create a Testing Table with Test Data?
  3. How To Insert a New Row into a Table with "INSERT INTO" Statements?
  4. How To Use Column Default Values in INSERT Statements?
  5. How to provide column names in INSERT Statements?
  6. What Happens If You Insert a Duplicate Key for the Primary Key Column?
  7. How To Insert Multiple Rows with One INSERT Statement?
  8. How To Update Values in a Table with UPDATE Statements?
  9. How To Update Multiple Rows with One UPDATE Statement?
  10. How to use old values to define new values in UPDATE statements?
  11. Is the Order of Columns in the SET Clause Important?
  12. How To Use Values from Other Tables in UPDATE Statements?
  13. What Happens If the UPDATE Subquery Returns No Rows?
  14. What Happens If the UPDATE Subquery Returns Multiple Rows?
  15. How To Delete an Existing Row with DELETE Statements?
  16. How To Delete Multiple Rows with One DELETE Statement?
  17. How To Delete All Rows with DELETE Statements?
  18. How To Delete All Rows with TRUNCATE TABLE Statement?

More...

SQL Server FAQs - Understanding SELECT Statements with Joins and Subqueries

A collection of 17 FAQs on SELECT statements with joins and subqueries. Clear answers are provided with tutorial exercises on joining multiple tables with inner and outer joins; using subqueries with IN, EXISTS, and FROM clauses; using UNION operations.

  1. How To Join Two Tables in a Single Query?
  2. How To Write a Query with an Inner Join?
  3. How To Define and Use Table Alias Names?
  4. How To Write a Query with a Left Outer Join?
  5. How To Write a Query with a Right Outer Join?
  6. How To Write a Query with a Full Outer Join?
  7. How To Write an Inner Join with the WHERE Clause?
  8. How To Name Query Output Columns?
  9. What Is a Subquery in a SELECT Query Statement?
  10. How To Use Subqueries with the IN Operators?
  11. How To Use Subqueries with the EXISTS Operators?
  12. How To Use Subqueries in the FROM Clause?
  13. How To Count Groups Returned with the GROUP BY Clause?
  14. How To Return the Top 5 Rows from a SELECT Query?
  15. How To Return the Second 5 Rows?
  16. How To Use UNION to Merge Outputs from Two Queries Together?
  17. How To Use ORDER BY with UNION Operators

More...

SQL Server FAQs - Understanding SELECT Statements and GROUP BY Clauses

A collection of 20 FAQs on SQL SELECT query statements. Clear answers are provided with tutorial exercises on simple SELECT query to select specific rows and returning specific columns; applying group aggregation functions on selected rows; dividing selected rows into multiple groups using GROUP BY and HAVING conditions; sorting selected rows and groups.

  1. What Is a SELECT Query Statement?
  2. How To Create a Testing Table with Test Data?
  3. How To Select All Columns of All Rows from a Table with a SELECT statement?
  4. How To Select Some Specific Columns from a Table in a Query?
  5. How To Select Some Specific Rows from a Table?
  6. How To Add More Data to the Testing Table?
  7. How To Sort the Query Output with ORDER BY Clauses?
  8. Can the Query Output Be Sorted by Multiple Columns?
  9. How To Sort Query Output in Descending Order?
  10. How To Count Rows with the COUNT(*) Function?
  11. Can SELECT Statements Be Used on Views?
  12. How To Filter Out Duplications in the Returning Rows?
  13. What Are Group Functions in Query Statements?
  14. How To Use Group Functions in the SELECT Clause?
  15. Can Group Functions Be Mixed with Non-group Selection Fields?
  16. How To Divide Query Output into Multiple Groups with the GROUP BY Clause?
  17. How To Apply Filtering Criteria at Group Level with The HAVING Clause?
  18. How To Count Duplicated Values in a Column?
  19. Can Multiple Columns Be Used in GROUP BY?
  20. Can Group Functions Be Used in the ORDER BY Clause?

More...

SQL Server FAQs - Introduction To Transact-SQL Language Basics and Data Types

A collection of 19 FAQs on Transact-SQL language basics and data types. Clear answers are provided with tutorial exercises on writing Transact-SQL statements; entering comments; ending and running statement batches; GO and PRINT statements; exact and approximate numeric data types; data and time, Unicode character strings and binary strings.

  1. What Is SQL Language?
  2. What Is Transact-SQL Language?
  3. What Is a Transact-SQL Statement?
  4. How To Start and End Transact-SQL Statements?
  5. How To Enter Comments in Transact-SQL Statements?
  6. What Is a Transact-SQL Statement Batch?
  7. What Happens to a Statement Batch If There Is a Compilation Error?
  8. How To Use GO Command in "sqlcmd"?
  9. How To Create User Messages with PRINT Statements?
  10. How Many Categories of Data Types Used by SQL Server?
  11. What Are Exact Numeric Data Types?
  12. What Are Approximate Numeric Data Types?
  13. What Are Date and Time Data Types?
  14. What Are Character String Data Types?
  15. What Are Unicode Character String Data Types?
  16. What Are Binary String Data Types?
  17. What Are the Differences between CHAR and NCHAR?
  18. What Are the Differences between CHAR and VARCHAR?
  19. What Are the Differences between DECIMAL and FLOAT?

More...

SQL Server FAQs - Transact-SQL Constants/Literals and Value Ranges

A collection of 18 FAQs on Transact-SQL language data constants or literals and value ranges. Clear answers are provided with tutorial exercises on entering data constants or literals; quoted character strings; date and time formats and ranges; integer and exact number literals; floating number precisions and ranges.

  1. What Is a Constant or Literal?
  2. How To Write Character String Constants or Literals?
  3. What Is a Collation?
  4. How To Specify the Collation for a Character Data Type?
  5. What Happens If Strings Are Casted into Wrong Code Pages?
  6. How To Find Out What Is the Default Collation in a Database?
  7. How Fixed Length Strings Are Truncated and Padded?
  8. How To Enter Unicode Character String Literals?
  9. How To Enter Binary String Literals?
  10. How To Enter Date and Time Literals?
  11. Why I Can Not Enter 0.001 Second in Date and Time Literals?
  12. What Happens If Date-Only Values Are Provided as Date and Time Literals?
  13. What Happens If Time-Only Values Are Provided as Date and Time Literals?
  14. What Are Out-of-Range Errors with Date and Time Literals?
  15. What Happens If an Integer Is Too Big for INT Date Type?
  16. How Extra Digits Are Handled with NUMERIC Data Type Literals?
  17. How REAL and FLOAT Literal Values Are Rounded?
  18. What Are the Underflow and Overflow Behaviors on FLOAT Literals?

More...

SQL Server FAQs - Transact-SQL Numeric Expressions and Functions

A collection of 14 FAQs on Transact-SQL language numeric expressions and functions. Clear answers are provided with tutorial exercises on writing numeric expressions; arithmetic operations; implicit data type conversions; explicit data type conversions; mathematical functions, random number generations.

  1. What Is an Expression?
  2. What Are Arithmetic Operators?
  3. What Happens to an Arithmetic Operation with Two Different Data Types?
  4. How To Convert a Numeric Expression from One Data Type to Another?
  5. How To Convert Numeric Expression Data Types by Assignment Operations?
  6. How To Convert Numeric Expression Data Types using the CAST() Function?
  7. How To Convert Numeric Expression Data Types using the CONVERT() Function?
  8. How To Convert Character Strings into Numeric Values?
  9. What Happens When Converting Big Values to Integers?
  10. What Happens When Converting Big Values to NUMERIC Data Types?
  11. What Are the Mathematical Functions Supported by SQL Server 2005?
  12. How To Convert Numeric Values to Integers?
  13. How To Round a Numeric Value To a Specific Precision?
  14. How To Generate Random Numbers with the RAND() Function?

More...

SQL Server FAQs - Transact-SQL Managing Character Strings and Binary Strings

A collection of 14 FAQs on Transact-SQL language character string and binary string operations. Clear answers are provided with tutorial exercises on concatenating character/binary strings; converting Unicode character strings; converting binary strings; inserting new line characters; locating and taking substrings; bitwise operations.

  1. How To Concatenate Two Character Strings Together?
  2. What Happens When Unicode Strings Concatenate with Non-Unicode Strings?
  3. How To Convert a Unicode Strings to Non-Unicode Strings?
  4. What Are the Character String Functions Supported by SQL Server 2005?
  5. How To Insert New Line Characters into Strings?
  6. How To Locate and Take Substrings with CHARINDEX() and SUBSTRING() Functions?
  7. How To Concatenate Two Binary Strings Together?
  8. Can Binary Strings Be Used in Arithmetical Operations?
  9. How To Convert Binary Strings into Integers?
  10. Can Binary Strings Be Converted into NUMERIC or FLOAT Data Types?
  11. Can Binary Strings Be Converted into Character Strings?
  12. Can Binary Strings Be Converted into Unicode Character Strings?
  13. How To Convert Binary Strings into Hexadecimal Character Strings
  14. What Are Bitwise Operations?

More...

SQL Server FAQs - Transact-SQL Date and Time Operations and Functions

A collection of 18 FAQs on Transact-SQL language date and time operations and functions. Clear answers are provided with tutorial exercises on converting date and time values to integers or decimal values; incrementing and decrementing date parts; taking date differences; formatting dates to strings; getting GMT times.

  1. How To Add or Remove Days on Date and Time Values?
  2. Can Date and Time Values Be Converted into Integers?
  3. Can Integers Be Converted into Date and Time Values?
  4. Are DATETIME and NUMERIC Values Convertible?
  5. Can a DATETIME Value Be Subtracted from Another DATETIME Value?
  6. What Are the Date and Time Functions Supported by SQL Server 2005?
  7. How To Increment or Decrement Parts of DATETIME Values?
  8. How To Use DATEADD() Function?
  9. How To Calculate DATETIME Value Differences Using the DATEDIFF() Function?
  10. How To Calculate Age in Days, Hours and Minutes?
  11. How To Get Month and Weekday Names from DATETIME Values?
  12. How To Get Parts of DATETIME Values as Integers?
  13. How To Get Year, Month and Day Out of DATETIME Values?
  14. What Is the Difference Between GETDATE() and GETUTCDATE()?
  15. How To Format Time Zone in +/-hh:mm Format?
  16. How To Format DATETIME Values to Strings with the CONVERT() Function?
  17. How To Truncate DATETIME Values to Dates without Time?
  18. How To Set Different Parts of a DATETIME Value?

More...

SQL Server FAQs - Transact-SQL Boolean Values and Logical Operations

A collection of 14 FAQs on Transact-SQL language Boolean values and logical operations. Clear answers are provided with tutorial exercises on getting Boolean values with comparison operations; CASE expressions; BETWEEN and IN comparisons; pattern match with LIKE operator; EXISTS and IN subquery expressions; AND and OR logical operations.

  1. What Is a Boolean Value?
  2. What Are Conditional Expressions?
  3. What Are Comparison Operations?
  4. How To Perform Comparison on Exact Numbers?
  5. How To Perform Comparison on Floating Point Numbers?
  6. How To Perform Comparison on Date and Time Values?
  7. How To Perform Comparison on Character Strings?
  8. What To Test Value Ranges with the BETWEEN Operator?
  9. What To Test Value Lists with the IN Operator?
  10. What To Perform Pattern Match with the LIKE Operator?
  11. How To Use Wildcard Characters in LIKE Operations?
  12. How To Test Subquery Results with the EXISTS Operator?
  13. How To Test Values Returned by a Subquery with the IN Operator?
  14. What Are Logical/Boolean Operations?

More...

SQL Server FAQs - Transact-SQL Conditional Statements and Loops

A collection of 5 FAQs on Transact-SQL language conditional statements and loops. Clear answers are provided with tutorial exercises on IF ... ELSE statements; WHILE loops; statement blocks; BREAK and CONTINUE statements.

  1. How To Use "IF ... ELSE IF ... ELSE ..." Statement Structures?
  2. How To Use "BEGIN ... END" Statement Structures?
  3. How To Use WHILE Loops?
  4. How To Stop a Loop Early with BREAK Statements?
  5. How To Skip Remaining Statements in a Loop Block Using CONTINUE Statements?

More...

SQL Server FAQs - Downloading and Installing Sample Scripts and Databases

A collection of 6 FAQs on download and installing SQL Server sample scripts and sample databases. Clear answers are provided with tutorial exercises on downloading and installing AdventureWorksLT; attaching AdventureWorksLT to SQL Server.

  1. What Samples and Sample Databases Are Provided by Microsoft?
  2. How to download and install SQL Server 2005 Sample Scripts?
  3. How to download and install the scaled-down database AdventureWorksLT?
  4. How to attach AdventureWorksLT physical files to the server?
  5. How AdventureWorksLT tables are related?
  6. How to add an address record into AdventureWorksLT?

More...

SQL Server FAQs - Understanding and Managing Indexes

A collection of 23 FAQs on SQL Server database indexes. Clear answers are provided with tutorial exercises on creating and dropping indexes; clustered and non-clustered indexes; indexes created by primary key and unique constraints; index fragmentation and rebuilding.

  1. What Are Indexes?
  2. How To Create an Index on an Existing Table?
  3. How To View Existing Indexes on an Given Table using SP_HELP?
  4. How To View Existing Indexes on an Given Table using sys.indexes?
  5. How To Drop Existing Indexes?
  6. Is the PRIMARY KEY Column of a Table an Index?
  7. Does the UNIQUE Constraint Create an Index?
  8. What Is the Difference Between Clustered and Non-Clustered Indexes?
  9. How To Create a Clustered Index?
  10. How To Create an Index for Multiple Columns?
  11. How To Create a Large Table with Random Data for Index Testing?
  12. How To Measure Performance of INSERT Statements?
  13. Does Index Slows Down INSERT Statements?
  14. Does Index Speed Up SELECT Statements?
  15. What Happens If You Add a New Index to Large Table?
  16. What Is the Impact on Other User Sessions When Creating Indexes?
  17. What Is Index Fragmentation?
  18. What Causes Index Fragmentation?
  19. How To Defragment Table Indexes?
  20. How To Defragment Indexes with ALTER INDEX ... REORGANIZE?
  21. How To Rebuild Indexes with ALTER INDEX ... REBUILD?
  22. How To Rebuild All Indexes on a Single Table?
  23. How To Recreate an Existing Index?

More...

SQL Server FAQs - Understanding and Managing Views

A collection of 20 FAQs on SQL Server database views. Clear answers are provided with tutorial exercises on creating and dropping views; defining and viewing view columns; creating views from multiple tables; inserting, updating and deleting data in underlying tables; creating schema binding view; creating indexes on views.

  1. What Are Views?
  2. How To Create a View on an Existing Table?
  3. How To See Existing Views?
  4. How To Drop Existing Views from a Database?
  5. How To Get a List of Columns in a View using "sys.columns"?
  6. How To Get a List of Columns in a View using the "sp_columns" Stored Procedure?
  7. How To Get a List of Columns in a View using the "sp_help" Stored Procedure?
  8. How To Generate CREATE VIEW Script on an Existing View?
  9. Can You Create a View with Data from Multiple Tables?
  10. Can You Create a View using Data from Another View?
  11. What Happens If You Delete a Table That Is Used by a View?
  12. Can You Use ORDER BY When Defining a View?
  13. How To Modify the Underlying Query of an Existing View?
  14. Can You Insert Data into a View?
  15. Can You Update Data in a View?
  16. Can You Delete Data from a View?
  17. How To Assign New Column Names in a View?
  18. How Column Data Types Are Determined in a View?
  19. How To Bind a View to the Schema of the Underlying Tables?
  20. How To Create an Index on a View?

More...

SQL Server FAQs - Transact-SQL Understanding Stored Procedures

A collection of 19 FAQs on SQL Server Transact-SQL stored procedures. Clear answers are provided with tutorial exercises on creating and dropping stored procedures; retrieving and modifying stored procedures; ending stored procedures properly; defining and passing values through input and output parameters; temporary and permanent stored procedures.

  1. What Are Stored Procedures?
  2. How To Create a Simple Stored Procedure?
  3. How To Execute a Stored Procedure?
  4. How To List All Stored Procedures in the Current Database?
  5. How To Drop an Existing Stored Procedure?
  6. How To Create a Stored Procedure with a Statement Block?
  7. How To End a Stored Procedure Properly?
  8. How To Generate CREATE PROCEDURE Script on an Existing Stored Procedure?
  9. How To Get the Definition of a Stored Procedure Back?
  10. How To Modify an Existing Stored Procedure?
  11. How To Create Stored Procedures with Parameters?
  12. How To Provide Values to Stored Procedure Parameters?
  13. What Are the Advantages of Passing Name-Value Pairs as Parameters?
  14. Can You Pass Expressions to Stored Procedure Parameters?
  15. How To Provide Default Values to Stored Procedure Parameters?
  16. How To Define Output Parameters in Stored Procedures?
  17. How To Receive Output Values from Stored Procedures?
  18. How To Create a Local Temporary Stored Procedure?
  19. Can Another User Execute Your Local Temporary Stored Procedures?

More...

SQL Server FAQs - Transact-SQL Understanding User_Defined_Functions

A collection of 17 FAQs on SQL Server Transact-SQL user defined functions. Clear answers are provided with tutorial exercises on creating and dropping user defined functions; defining and passing parameters into functions; providing and using parameter default values; defining and using table-valued functions. Topics included in this FAQ are:

  1. What Are User Defined Functions?
  2. What Are the Differences between User Defined Functions and Stored Procedures?
  3. How To Create a Simple User Defined Function?
  4. How To Use User Defined Functions in Expressions?
  5. How To List All User Defined Functions in the Current Database?
  6. How To Drop an Existing User Defined Function?
  7. How To Generate CREATE FUNCTION Script on an Existing Function?
  8. How To Get the Definition of a User Defined Function Back?
  9. How To Modify an Existing User Defined Function?
  10. How To Create User Defined Functions with Parameters?
  11. How To Provide Values to User Defined Function Parameters?
  12. Can You Pass Expressions to Function Parameters?
  13. How To Provide Default Values to Function Parameters?
  14. How Many Categories of Functions based Their Return Modes?
  15. How Many Ways to Create Table-Valued Functions?
  16. How To Create an Inline Table-Valued Function?
  17. How To Create an Multi-Statement Table-Valued Function?

SQL Server FAQs - Creating and Managing Schemas

A collection of 11 FAQs on SQL Server on creating and managing schemas. Clear answers are provided with tutorial exercises on listing all schemas and all objects in a schema; transferring tables from one schema to another schema; changing ownership of a schema.

  1. What Is a Schema in SQL Server 2005?
  2. How To Create a New Schema in a Database?
  3. How To List All Schemas in a Database?
  4. How To Create a New Table in a Given Schema?
  5. How To Transfer an Existing Table from One Schema to Another Schema?
  6. How To List All Objects in a Given Schema?
  7. What Is the Default Schema of Your Login Session?
  8. Who Is the Owner of a Schema?
  9. How To Change the Ownership of a Schema?
  10. What Happens If You Are Trying to Access a Schema Not Owned by You?
  11. How To Drop an Existing Schema?

More...

SQL Server FAQs - Security - Server Login and Database User

A collection of 17 FAQs on SQL Server logins and users. Clear answers are provided with tutorial exercises on security model; security principals, securables and permissions; creating, changing and dropping login names; linking users with logins.

  1. What Is the Security Model Used in SQL Server 2005?
  2. What Are Security Princ


Make a free website Webnode