Program of sql with example




















Green Tech. MVP Award Program. Video Hub Azure. Microsoft Business. Microsoft Enterprise. Browse All Community Hubs. Turn on suggestions.

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type. Showing results for. Show only Search instead for. Did you mean:. Sign In. Tariq Rasheed Al-Qaralleh. Published Jan 09 AM 1, Views. I created a simple web site with a few lines of code: Added System.

Data and System. SqlClient Namespaces. Create connection, command and Data Adapter objects to execute an SQL command and fill the data table object.

The command is a Select command query on one of database tables and the result set is filtered by email address, the value that is entered by the user before hitting search button. The result will be shown on a grid view object on the page. The Web Page code: using System; using System. Generic; using System. A SqlConnection object is created. This object is used to open a connection to a database.

The using statement releases the database connection resource when the variable goes out of scope. The SqlCommand is an object which is used to execute a query on the database. The parameters are the SQL statement and the connection object. There are queries which return only a scalar value. In our case, we want a simple string specifying the version of the database. The ExecuteScalar is used in such situations.

First we drop the table if it already exists. The cars table is created. In SQL Server, an auto-incremented column is created with the identity property. Prepared statements increase security and performance. When we write prepared statements, we use placeholders instead of directly writing the values into the statements.

Prepared statements are faster and guard against SQL injection attacks. Example 7: Using String Functions. There are situations where user need to handle the different strings using multiple string functions.

There are so many situations where user needs to handle the validations of the string. In those cases user needs to use different string functions. I will share you some most important examples of String functions which are used in real life. Example 8 : Use of joins. These queries are most used queries in adding any logic anywhere.

You might know that there is always relationship between two or more tables. The join queries are most used queries to achieve some business functionality. I have given real life examples of joins in my articles. Here i will give you some examples of joins which are used in real life. The second most important query asked in interview is how to find out the second highest salary of employee. In real world also some situations where user needs to find out the second highest content from the table.

The third example of join is using self join. I will give the Employee and its manager name example for self join. Select E. If you want to explore more joining examples kindly click here. Now we are moving from simple SQL queries to complex sql queries.

There are so many situations where we need to catch the data by using multiple sets. In that cases set operators in SQL are useful. There are situations where user needs to handle the parent child relationship in the table.



0コメント

  • 1000 / 1000