Latest Added Tutorials
Before using the script below, an empty database is created and then it scans all the tables in the other database and transfers them with their data.
Note: If you are using a custom schema, for example sm_log, you must create it first!Continue Reading
20-11-2022
FROM mcr.microsoft.com/azure-sql-edge:latest
EXPOSE 1433
ENV SA_PASSWORD "12_34_TRS_398?"
ENV SQLCMDPASSWORD "12_34_TRS_398?"
ENV ACCEPT_EULA "Y"
RUN mkdir -p /opt/mssql-tools/bin && cd /opt/mssql-tools/bin && wget https://github.com/microsoft/go-sqlcmd/releases/download/v0.8.0/sqlcmd-v0.8.0-linux-arm64.tar.bz2 \
&& bzip2 -d sqlcmd-v0.8.0-linux-arm64.tar.bz2 && tar -xvf sqlcmd-v0.8.0-linux-arm64.tar && chmod 755 sqlcmd
RUN /opt/mssql/bin/sqlservr & sleep 20 && opt/mssql-tools/bin/sqlcmd -S localhost -U sa -d master
#ADD test.bak var/test.ba...Continue Reading
Base Model for Laravel Mssql Datetime Configuration
use Illuminate\Database\Eloquent\Model;
abstract class BaseModel extends Model
{
protected $dateFormat = 'Y-m-d H:i:s.u';
public function getDateFormat()
{
return 'Y-m-d H:i:s.u';
}
public function fromDateTime($value)
{
return substr(parent::fromDateTime($value), 0, -3);
}
}...Continue Reading
17-02-2018
We can
Category Table
CREATE TABLE category
(
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(50) NULL,
url VARCHAR(50) NULL,
parent INT NULL,
created_at TIMESTAMP NULL,
updated_at TIMESTAMP NULL,
deleted_at TIMESTAMP NULL,
resim VARCHAR(255) NULL,
kisaltma VARCHAR(255) NOT NULL,
CONSTRAINT category_category_parent_fk
FOREIGN KEY (parent) REFERENCES category (id)
ON DELETE SET NULL
)
ENGINE = InnoDB
COLLATE = utf8_unicode_ci;
CREATE INDEX category_category_parent_fk...Continue Reading
07-08-2017
Event::listen('Illuminate\Database\Events\QueryExecuted', function ($query) {
if (App::environment() == 'local') {
Log::info($query->sql . ' Parameters: ' . serialize($query->bindings));
}
});...Continue Reading
11-05-2017
We can connect msql server as follows:
$serverName = "127.0.0.1";
$uid = "sa";
$pwd = "123456!";
$databaseName = "TEST";
$connectionInfo = array("UID" => $uid,
"PWD" => $pwd,
"Database" => $databaseName,
"CharacterSet" => "UTF-8");
//Connect using SQL Server Authentication.
$conn = sqlsrv_connect($serverName, $connectionInfo);
$tsql = "SELECT * FROM fatura";
// Execute the query.
$stmt = sqlsrv_query($conn, $tsql);
$row = sqlsrv_fetch_array($stmt);
if (stmt) {
echo "Statement executed";
} else {
echo "Error in statement execut...Continue Reading
Question:
1. What is the reason for setting MappedBy in bidirectional many-to-many relationships?
2. When one table has significant amount of records, while other has a few, which side is better to put mappedBy
Answer:
It's actually a good question, and it helps to understand the concept of an "owning" entity. If you want to prevent both sides (in a bidirectional relationship) from having join tables, a good idea, then you need to have a mappedBy= element on one side.
Whether or not there is a join table is controlled by the mappedBy="name" el...Continue Reading
1. First of all, create a new mysql user:
mysql -u root -p
create user 'olyanren'@'%' identified by '123456';
grant all priviliges on *.* to 'olyanren'@'%' with grant option;
Note: Change olyanren username and password 123456. Also note that don't delete single quotas.
The key point is wildcard (%). By using wildcard, we give olyanren user an access right to connect from any host.
After these steps, confirm if the new user olyanren has been created
select user, host from mysql.user;
2) Restart mysql service mysqld restart
...
OneToMany Unidirectional Mapping
Question:
In this document (scroll down to the Unidirectional section): http://docs.jboss.org/hibernate/stable/annotations/reference/en/html_single/#entity-mapping-association-collections
It says that a unidirectional one-to-many association with a join table is much preferred to just using a foreign key column in the owned entity. My question is, why is it much preferred?
Answer 1:
Consider the situation where the owned entity type can also be owned by another parent entity type. Do you put foreign key refere...Continue Reading
For most developers, writing almost the same code for every DAO in an application has become indespensible. To solve this problem and to rescue developers from copying and pasting same codes into every dao classes, we will use DAO pattern.
In this tutorial, I will show you how to create dao pattern in a spring application. The foundation of using a Generic DAO is the CRUD operations that you can perform on each entity.
Generic Dao Implementation
Model Class
Hibernate ORM framework uses model classes for database tables. Therefore we need to creat...Continue Reading
22-01-2015
To set the default to UTF-8, you want to add the following to my.cnf or my.ini for Windows
[mysqld]
collation-server = utf8_unicode_ci
character-set-server = utf8
If you want to change the character set for an existing DB, you can use following code:
ALTER DATABASE databasename CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE tablename CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;...Continue Reading
To convert yyyymmddhhmmss string format to datetime in Microsoft Sql Server, you can use below sql script:
update PageContent
set NewDatetimeColumn = convert(datetime, stuff(stuff(stuff(OldDateAsStringColumn, 9, 0, ' '), 12, 0, ':'), 15, 0, ':'))
NewDatetimeColumn column is defined in the PageContent table and will be used to store OldDateAsStringColumn's string value after conversion operation.
After run this script, for example, 20090513024903 string value will be 2009-05-13 02:49:03.000...Continue Reading
23-12-2014
If you want to change some string content of a column, you can use REPLACE function as follow:
UPDATE urls
SET url = REPLACE(url, 'domain1.com/images/', 'domain2.com/otherfolder/')
urls: Table Name
url: Column Name
REPLACE function first parameter is column name, second parameter string value to be changed, and third parameter is new string value....Continue Reading
24-06-2014
The transaction isolation levels in JDBC help us to determine whether the concurrently running transactions in a DB can affect each other or not. If there are 2 or more transactions concurrently accessing the same DataBase, then we need to prevent the actions of the transactions from interfering with each other. The above is achieved using the isolation levels in JDBC....Continue Reading
18-06-2014
The addition of JDBC connection pooling to your application usually involves little or no code modification but can often provide significant benefits in terms of application performance, concurrency and scalability. Improvements such as these can become especially important when your application is tasked with servicing many concurrent users within the requirements of sub second response time. ...Continue Reading