Found 6702 Articles for Database

MySQL “not a variable or NEW pseudo-variable” message. What is this error in my Stored Procedure?

Samual Sam
Updated on 30-Jul-2019 22:30:24

1K+ Views

To get rid of this error message, let us see a sample example. But before that let us go through the concept to fix it.Use variable to get the value from stored procedure. The variable will prefix with @ symbol. The syntax is as follows −CALL yourStoredProcedureName(yourParameter1, yourParameter2, ..........N, @yourVariableName);To see the value of variable you need to use select statement. The syntax is as follows −SELECT @yourVariableName;To understand the above syntax, let us create a table and insert some records in the table.The query to create a table is as follows −mysql> create table StoredProcedureDemo    -> (   ... Read More

Using LIKE for two where clauses in MySQL?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:24

127 Views

You don’t need to use two where clauses. Use two conditions using the LIKE operator and AND operator.To understand how to use LIKE for this, let us create a table. The query to create a table is as follows −mysql> create table WhereDemo    -> (    -> Id int,    -> Name varchar(20)    -> ); Query OK, 0 rows affected (0.56 sec)Now you can insert some records in the table using insert command. The query is as follows −mysql> insert into WhereDemo values(101, 'Maxwell'); Query OK, 1 row affected (0.14 sec) mysql> insert into WhereDemo values(110, 'David'); Query ... Read More

Resolve usage of quotes ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use?

Samual Sam
Updated on 30-Jul-2019 22:30:24

10K+ Views

In MySQL, you can use two different types of quotation marks which is backtick and another is single quotes or double quotes. In this case, maybe you are using single quotes to the column name that’s why you are getting error. You need to use the backtick symbol (` `) instead of single quotes. Backtick can be used with column names while single quotes can be used for strings.To understand the above error, let us create a table. The query to create a table is as follows −mysql> create table Backtick_SymbolDemo    -> (    -> Id int NOT NULL ... Read More

Should I store a field PRICE as an int or as a float in the database?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:24

651 Views

You do not need to store a field PRICE as an int or as float in the database. For this, you can set the DECIMAL()..Most of the time integers can be used to represent the float point numbers and these integers are internally cast into DECIMAL() data type. Therefore, if you have field PRICE then always use DECIMAL() data type. The syntax is as follows −DECIMAL(M, D);Here, M represents the ‘TotalNumberOfDigit’ and D represents the ‘Number OfDigitAfterDecimalPoint’.To understand the above concept, let us create a table with field PRICE as DECIMAL data type. The query is as follows −mysql> create ... Read More

MySQL how to declare a datetime variable?

Samual Sam
Updated on 30-Jul-2019 22:30:24

2K+ Views

To declare a datetime variable, you need to use a user-defined variable using the SET command. The syntax is as follows −SET @anyVariableName=’yourdatetimeValue’;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table datetimeVariables -> ( -> Id int NOT NULL AUTO_INCREMENT, -> Name varchar(10), -> ArrivalDatetime datetime, -> PRIMARY KEY(Id) -> ); Query OK, 0 rows affected (0.78 sec)Insert some records in the table using insert command. The query to ... Read More

Return order of MySQL SHOW COLUMNS?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:24

246 Views

To return order of MySQL SHOW COLUMNS, you need to use ORDER BY clause. The syntax is as follows −SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = ‘yourTableName’ AND column_name LIKE 'yourStartColumnName%' ORDER BY column_name DESC;Let us create a table in database TEST. The query to create a table is as follows −mysql> create table OrderByColumnName -> ( -> StudentId int, -> StudentFirstName varchar(10), -> StudentLastName varchar(10), -> StudentAddress varchar(20), -> StudentAge int, -> StudentMarks int ... Read More

Resolve an error whenever multiple rows are returned in MySQL Benchmark?

Samual Sam
Updated on 30-Jul-2019 22:30:24

188 Views

You will get an error whenever you return multiple rows in the benchmark. Return a scalar value or single row instead of multiple rows. The syntax is as follows −SELECT yourColumnName FROM yourTableName WHERE yourCondition.To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table UserDemo    -> (    -> UserId int,    -> UserName varchar(20),    -> RegisteredCourse varchar(10)    -> ); Query OK, 0 rows affected (0.67 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into UserDemo values(1, ... Read More

Inserting records into a MySQL table using PreparedStatement in Java?

karthikeya Boyini
Updated on 30-Jun-2020 12:58:22

4K+ Views

To insert a record in the table using PreparedStatement in Java, you need to use below syntax to insert records. The syntax is as follows −String anyVariableName= "INSERT INTO yourTableName(yourColumnName1, yourColumnName2, yourColumnName3, .........N)" + "VALUES (?, ?, ?, ..............N)";Now use the PreparedStatement object to set the value for all columns. The syntax is as follows −PreparedstatementObject = con.prepareStatement(query); PreparedstatementObject .setXXX(1, yourValue); PreparedstatementObject .setXXX(2, yourValue); PreparedstatementObject .setXXX(3, yourValue); . . . NThe above prepared statement will solve your problem. Now first create a table in MySQL. The query to create a table is as follows −mysql> create table CourseDemo -> ( ... Read More

MySQL Query to get count of unique values?

Samual Sam
Updated on 30-Jul-2019 22:30:24

382 Views

To count the unique values on a column, you need to use keyword DISTINCT. To understand how it is done, let us create a table. The query to create a table is as follows −mysql> create table UniqueCountByIPAddress    -> (    -> Id int NOT NULL AUTO_INCREMENT,    -> UserHits int,    -> UserIPAddress varchar(50),    -> PRIMARY KEY(Id)    -> ); Query OK, 0 rows affected (0.69 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into UniqueCountByIPAddress(UserHits, UserIPAddress) values(10, '127.0.0.1'); Query OK, 1 row affected (0.20 sec) mysql> insert into ... Read More

MySQL- GROUP and COUNT by date?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:24

2K+ Views

You can use GROUP BY clause and COUNT() function for this. The syntax is as follows −SELECT yourColumnName1, yourColumnName2, ..N, COUNT(*) as anyAliasName FROM yourTableName GROUP BY yourColumnName1, yourColumnName2;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table GroupAndCountByDate    -> (    -> Id int NOT NULL AUTO_INCREMENT,    -> TripDate date,    -> ShopId int,    -> PRIMARY KEY(Id)    -> ); Query OK, 0 rows affected (0.79 sec)Now you can insert some records in the table using insert command. The query is as follows −mysql> ... Read More

Advertisements