MySQL Alter Query [duplicate] - mysql

This question already has answers here:
How to store phone numbers on MySQL databases? [duplicate]
(11 answers)
Closed 5 years ago.
I want to add a column in Customers table. The name of the column which I want to add, is Phone_no. Now if I want to add the country code along with the Phone_no field , then what would be the data type of Phone_no ? e.g. the Phone_no is +918884560909 , Then what would be the data type of Phone_no field?

If you want to add the number with special symbol like +, then use varchar for it like:
varchar(20)

If you prefer one field name it as varchar(expected_size). If you prefer two fields you can name one field as country code (varchar) and other as phone_no(number). Go through Oracle documentation for all available datatypes.

ALTER TABLE Customers ADD COLUMN Phone-no varchar(13);
You could just store number without +. In that case you could store number as bigint

Related

Check if table row contains already inserted string value in MySQL [duplicate]

This question already has answers here:
Prevent duplicate values in database - mysql
(2 answers)
Closed 4 months ago.
Long story short,
I'm trying to create a table, where you can enter a company name. However you cannot enter a company name which contains a string value of a previous entered company name. Is this possible to do with a check constraint?
For example:
My company "CrazyJello" is inserted. Now the following companies that are being entered to MySQL cannot have the string "Crazy" in them.
CREATE table company(
name VARCHAR (100)
CHECK (name != ?????)
No, in sql there is the unique index, but it compares the whole content of the field https://www.mysqltutorial.org/mysql-unique/

How can i combine the values from 3 varchar columns to one column? [duplicate]

This question already has answers here:
MYSQL - add new column with default string concat with data from existing column
(2 answers)
String concatenation in MySQL
(5 answers)
Closed 11 months ago.
For Example
I have the following Columns in a DB-table: Name, Surname, Adress, Contact.
In one row the value for the column name is Smith , the surname Bob and the adress Street1.
How can i combine the mentioned values to the column Contact?
The Value in this row should be like this then:
Bob_Smith_Street1
I want this to be automatically created in the table. so as soon as I right click on the Table -->select 1000 rows, the value is displayed. Without having me to enter the mentioned select command. Is this possible? Can anything be done when creating the table for this. So for example create table employees (Contact(name""surname""address)).
thanks
ps. sorry for my bad english:)
Use CONCAT(). For example:
select concat(Name, '_', Surname, '_', Adress) as contact from t

How to change All column name as lower case in Mysql table? [duplicate]

This question already has answers here:
Mysql - Rename all tables and columns to lower case?
(6 answers)
How to automatically convert a MySQL column to lowercase
(3 answers)
Closed 4 years ago.
A MySQL table contains almost 17 fields. for example
P_ID
P_NAME
P_ADDRESS
P_SERVICENO
etc..
how to change these all field name as lower case in a single query in MySQL.
Check this:
ALTER TABLE `table_name`
CHANGE P_ID p_id varchar(10),
CHANGE P_NAME p_name varchar(10),
...

Retrieve data from two table using id [duplicate]

This question already has answers here:
SQL query return data from multiple tables
(6 answers)
Closed 5 years ago.
Table1
Id, name, addresses
101,raja ,chennai
Table2
Id,group,name
101,a,siva
102,b,selva
I want retrieve data from two tables like
Table2.group=a and two table Id must equal then take address from table1 display
Id, name, Address, group
What have you tried so far? Have you taken a look at some of the resources here?
Since this is the type of pretty straightforward SQL query you're likely to do many times over, it's worth you reading the tutorials and learning it yourself. I'll give you a few pointers to begin:
Your two tables are connected by the Id field (most likely, this is the primary key for one table and the foreign key for another). You'll need to JOIN these two tables using that field.
You'll need to specify a WHERE clause to filter for your condition that Table2.group = a.
The fields you want to display can all be specified using SELECT. If you are selecting data FROM Table 1 and joining to Table 2, you won't need to specify the table name before the field name.

place an existing column at first position in mysql [duplicate]

This question already has answers here:
How to rearrange MySQL columns?
(6 answers)
Closed 9 years ago.
please tell me how to place an existing column(contained values) at first position in mysql. Suppose i have a table EMP_DTLS and there are columns like NAME, SALARY, DOJ, DOB, EMAIL_ID, AND EMP_ID contains values in every columns. Now i want to place this EMP_ID at first position.
Thanks in advance.
I have tried the queries those are discussed here previously but those aren't working for me.
ALTER TABLE EMP_DTLS MODIFY COLUMN EMP_ID INT(10) FIRST
Just use the correct type,i used INT(10)