Browsed by
Tag: Top Interview Questions on MySQL

Syntax and Queries

Syntax and Queries

MySQL Commands: Show databases; Create database db_name; Use dbname; Show tables; Create table tb_name(id int, name varchar(20)); Desc tb_name; Insert into tb_name values(101 , ‘name of person’); Insert into tb_name (id) values(102); Update tb_name set name=’person name’ where id=102; Select * from tb_name; Delete from tb_name where id=102; Drop table tb_name; Drop database db_name; Rename table tb_old_name to tb_new_name; Alter table customer add (remark varchar(20)); Alter table customer modify remark varchar(25); Alter table customer modify remark varchar(20); Alter table customer…

Read More Read More

How will Show all records containing the name “sonia” AND the phone number ‘9876543210’

How will Show all records containing the name “sonia” AND the phone number ‘9876543210’

mysql> SELECT * FROM tablename WHERE name = “sonia” AND phone_number = ‘9876543210’ To retrieve records containing the name “sonia” and the phone number ‘9876543210’ in MySQL, you can use the SELECT statement with the WHERE clause. Here’s an example query: sql SELECT * FROM your_table_name WHERE name = ‘sonia’ AND phone_number = ‘9876543210’; Make sure to replace your_table_name with the actual name of your table where the data is stored. This query will return all records where the name…

Read More Read More

Change column name and Make a unique column so we get nodupes

Change column name and Make a unique column so we get nodupes

mysql> alter table [table name] change [old column name] [new column name] varchar (50); mysql> alter table [table name] add unique ([column name]); To change the column name and make it unique in MySQL, you can use the ALTER TABLE statement. Assuming you want to change the column name from old_column to new_column and make it unique, you can execute the following SQL command: sql ALTER TABLE your_table CHANGE COLUMN old_column new_column datatype UNIQUE; Replace your_table with the name of…

Read More Read More

How to Show all records starting with the letters ‘sonia’ AND the phone number ‘9876543210’

How to Show all records starting with the letters ‘sonia’ AND the phone number ‘9876543210’

mysql> SELECT * FROM tablename WHERE name like “sonia%” AND phone_number = ‘9876543210’; To retrieve records in MySQL that start with the letters ‘sonia’ and have the phone number ‘9876543210’, you can use the SELECT statement with the LIKE operator for the name and a simple equality condition for the phone number. Here’s an example query: sql SELECT * FROM your_table_name WHERE name LIKE ‘sonia%’ AND phone_number = ‘9876543210’; Make sure to replace your_table_name with the actual name of your…

Read More Read More

How to make a column bigger and Delete unique from table

How to make a column bigger and Delete unique from table

mysql> alter table [table name] modify [column name] VARCHAR(3); mysql> alter table [table name] drop index [colmn name]; To make a column bigger in MySQL, you can use the ALTER TABLE statement along with the MODIFY COLUMN clause. Here’s an example: sql ALTER TABLE your_table_name MODIFY COLUMN your_column_name new_data_type; Replace your_table_name with the name of your table, your_column_name with the name of the column you want to modify, and new_data_type with the new data type and size you want to…

Read More Read More