Tag: database
How to Display list of databases on a MySQL?
If you want to display the list of databases in a MySQL server, you can use the command ‘show databases’. How to Display list of databases on a MySQL?
CASE expression in a Query in SQL Server
You can use the CASE expression in a T-SQL query in SQL Server to get the same behavior of the switch statement in the programming languages. Below is a sample Query demonstrating the implementation of the CASE expression in a query in SQL Server. CASE expression in a Query in SQL Server The query associates a Department group name to a country USA and UK…
How to select N random rows using a T-SQL Query ?
You can use the TOP keyword and specify the number to retreive the TOP N records that the query returns. Additionally , order the records by newid() function using the ORDER BY clause to make the records random. How to select N random rows using a T-SQL Query ?
Using FETCH and OFFSET to get N records in SQL Server
In SQL Server , you can use the OFFSET and FETCH and apply paging and retreive N records at a time. OFFSET AND FETCH clause are part of the ORDER BY clause and hence you must include the ORDER BY clause. For example , you might want to skip the first 4 records and retrieve 5 records from the query , you could use the…
Get the date in YYYY-MM-DD format in SQL Server.
You can retreive the date in the YYYY-MM-DD format in SQL Server using the CONVERT method as shown in this code snippet. How to get the date in YYYY-MM-DD format in SQL Server ?
How to get the Size of all tables in a SQL Server ?
In SQL Server 2014 Management Studio , you can get the size of all tables in a SQL Server from the Object explorer details window. How to get the Size of all tables in a SQL Server ? 1. In SQL Management Studio 2014 , navigate to the Object explorer details screen from View -> Object explorer details menu or by simply pressing the F7…
How to disable Foreign Key constraints using T-SQL in SQL Server ?
You can enable or disable the foreign key constraints for a table in a SQL Server using the ALTER statement. How to disable Foreign Key constraints using T-SQL in SQL Server ? Here’s the T-SQL query to disable all the constraints of the table “Employee”. If you want to enable all the constraints of the table , here’s how you do it.
Inserting a line break in the NVARCHAR data in SQL Server
For inserting the character break in a data of type NVARCHAR in SQL Server , you can use CHAR(13). Inserting a line break in the NVARCHAR data in SQL Server Inserting a line break in the NVARCHAR data in SQL Server
How to drop a table if it exists in SQL Server 2014 ?
Assume that you want to write a SQL Query in SQL Server which checks if the table exists in database and want to drop it , you can use the OBJECT_ID function to determine the table existence by passing the table name and the ‘U’ as parameters. How to drop a table if it exists in SQL Server 2014 ?
How to get the first character of a string in SQL Server ?
Assume a scenario where you have a column in your table in SQL Server database where you want to retreive the first character of the column value. How to get the first character of a string in SQL Server ? You can use the LEFT function and specify the column name as well as the number of characters from left that you want to retreive.
Checking the version of a SQL Server using T-SQL
There are couple of ways in which you can retreive the version of the SQL Server using T-SQL. Checking the version of a SQL Server using T-SQL 1. using @@VERSION 2. Using SERVERPROPERTY function as shown
How to get the date part from the date time in SQL Server ?
If you are on SQL Server 2008 and higher version and want to get the date part of the datetime data in SQL Server , you can use the CONVERT method as shown in this post. How to get the date part from the date time in SQL Server ? If you want to get the current date leaving out the time from the datetime…