SQL Server Tutorials

How to attach a database file to SQL Server Express

Developers can attach a database file to an instance of SQL Server 2005 Express Edition by using the sqlcmd tool. They have to follow the next steps:

1. Open the command prompt on the server.

2. Connect to an instance of SQL Server 2005 Express Edition, from the command prompt, by …

Learn more

How to use SQL Delete statement

Web developer uses SQL Delete statement to remove one or more rows based on specified criteria:

DELETE FROM [table] WHERE [search_condition]

The following example removes a single matching row from the Clients table:

DELETE FROM Clients WHERE cli_id=’334-56-2289′

Note: If client record is linked to one or more records in other tables, for example ClientAccounts table, Web developer should delete linked records …

Learn more

How to use SQL Update statement

Web developer uses SQL Update statement to selects all the records that match a specified search expression and then to modify them all according to an update expression. At its simplest, the Update statement has the following format:

UPDATE [table] SET [update_expression] WHERE [search_condition]

Typically, the Update statement to is used to modify a single record. The following example adjusts …

Learn more

How to use SQL Insert statement.

Web developer can use the SQL Insert statement to add a new record to a table with the information he/she specifies:

INSERT INTO [table] ([column_list]) VALUES ([value_list])

Web developer can provide the information in any order he/she wants, as long as he/she makes sure the list of column names and the list of values correspond exactly:

INSERT INTO Clients (cli_id,cli_finame, …

Learn more

How to use aggregate SQL Select statements

Web developer can use special aggregate SQL functions which work with a set of values but return only a single value. For example, Web developer can use use an aggregate function to count the number of records in a table or to calculate the average price of a product:

     – Avg(fieldname) – Calculates the average of all values in …

Learn more

How to perform string matching with the SQL Like operator

Web developer can use the SQL Like operator to perform partial string matching to filter records where a particular field starts with, end with, or contains a certain sets of characters. For example, if Web developer wants to see all store applicants names that start with C, he/she could use the following statement:

SELECT * FROM Applicants WHERE appl_fname …

Learn more

How to use alternative SQL Select statement

Web developer can use the Top clause instead of a Where clause. For example:

SELECT TOP 100 * FROM Orders ORDER_BY ord_date DESC

The database rows will be sorted in descending order by order date, and the first 100 matching results will be retrieved. In this case, it’s the 100 most recent orders. Web developer could also use this type …

Learn more

How to use a Where clause in SQL Select statements.

In many cases, the Where clause is the most important part of the Select statement. Web developer can find records that match several conditions using the And keyword, and he/she can find records that match any one of a series of conditions using the Or keyword. Web developer can also specify greater-than and less-than comparisons by using the …

Learn more

How to improve SQL Select statement

The following is an example of typical and inefficient Select statement. It works with the Clients table:

SELECT * FROM Clients

-The asterisk (*) retrieves all the columns in the table. This isn’t the best approach for a large table if a Web developer does not need all the information. It increases the amount of data that has to be …

Learn more

How to use SQL Select statement

Web developer can retrieve one or more rows of data, by using SQL select statement which has the following structure:

SELECT [columns]
FROM [tables]
WHERE [search_condition]
ORDER BY [order_expression ASC | DESC]

Related TutorialsHow to show constraint properties in the Properties window in SQL server
How to delete XML indexes in SQL server
How to create a new database diagram in SQL Server Object Explorer
How …

Learn more