Found 4219 Articles for MySQLi

MySQL command to copy table?

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

303 Views

You can achieve this with the help of INSERT INTO SELECT statement. The syntax is as follows −INSERT INTO yourDatabaseName.yourTableName(SELECT *FROM yourDatabaseName.yourTableName);To understand the above syntax, let us create a table in a database and second table in another databaseThe database name is “bothinnodbandmyisam”. Let us create a table in the same database. The query is as follows −mysql> create table Student_Information    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> Name varchar(10),      -> Age int    -> ); Query OK, 0 rows affected (0.67 sec)Now you can insert some records in the ... Read More

MySQL CREATE USER with a variable?

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

830 Views

You can use a dynamic query for this. First set the variable name for username and variable name for a password. The syntax is as follows −SET @anyVariableName=’yourUserName’; SET @anyVariableName1=’yourpassword’;Now you can use the CONCAT() function from MySQL. The syntax is as follows −SET @yourQueryName = CONCAT ('    CREATE USER "', @anyVariableName, '"@"localhost" IDENTIFIED BY "', @anyVariableName1, '" ' );Let us use the prepared statement PREPARE. The syntax is as follows −PREPARE yourStatementVariableName FROM @yourQueryName;Now you can execute the statement. The syntax is as follows −EXECUTE yourStatementVariableName;Deallocate the above using the DEALLOCATE PREPARE. The syntax is as follows −DEALLOCATE ... Read More

Create MySQL column with Key=MUL?

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

4K+ Views

You need to use ADD KEY to make a column with Key=MUL. The syntax is as follows −ALTER TABLE yourTableName MODIFY COLUMN yourColumnName data type, ADD KEY(yourColumnName);To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table Instructor    -> (    -> Instructor_Id int,    -> Instructor_Name varchar(30),    -> Instructor_CourseName varchar(100)    -> ); Query OK, 0 rows affected (0.63 sec)Now you can look the table description of the table, the column KEY does not have any MUL key. The query is as follows to check the ... Read More

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

124 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

641 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

245 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

186 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

Advertisements