Found 6705 Articles for Database

How to change auto increment number in the beginning in MySQL?

Arjun Thakur
Updated on 24-Jun-2020 14:01:33

838 Views

The auto_increment is a default property that automatically increments the newly added record by 1. The auto_increment can be changed from the beginning as well. The procedure for that is given below −First, a table is created.mysql> CREATE table DemoAuto -> ( -> id int auto_increment, -> name varchar(100), -> primary key(id) -> ); Query OK, 0 rows affected (0.47 sec)After that the alter table command is used to change the starting number of auto_incremnt which starts from 1 by default. The starting value is changed to 100.mysql> alter table DemoAuto auto_increment = 100; Query OK, 0 rows affected (0.24 ... Read More

How to check if a MySQL database exists?

Chandu yadav
Updated on 24-Jun-2020 14:05:49

6K+ Views

The schema_name command is used to check if a MySQL database exists or not. The syntax of this command is as follows −select schema_name from information_schema.schemata where schema_name = 'database name';Now, the above command is used to check whether the database exists or not. The query for that is as follows −Case 1 − The database exists.mysql> select schema_name from information_schema.schemata where schema_name = 'business'; The output obtained is as follows −+-------------+ | SCHEMA_NAME | +-------------+ | business | +-------------+ 1 row in set (0.00 sec)Case 2 − The database does not exist.mysql> select schema_name from information_schema.schemata ... Read More

MySQL error 1452 - Cannot add or a child row: a foreign key constraint fails

Ankith Reddy
Updated on 24-Jun-2020 14:06:30

8K+ Views

To understand error 1452, first we need to create a table and relate that to another table with the help of a foreign key constraint.Creating the first table −mysql> CREATE table ForeignTable -> ( -> id int, -> name varchar(200), -> Fk_pk int -> ); Query OK, 0 rows affected (0.43 sec)After creating the first table successfully, we will create the second table −mysql> CREATE table primaryTable1 -> ( -> Fk_pk int, -> DeptName varchar(200), -> Primary key(Fk_pk) -> ); Query OK, 0 rows affected (0.48 sec)Now, we have created both tables. Then both the tables are related with the ... Read More

How to get the max of two values MySQL?

Arjun Thakur
Updated on 24-Jun-2020 14:07:00

1K+ Views

To get the maximum of two values in MySQL, we can use the predefined function “greatest”. The syntax of greatest() function is as follows −SELECT greatest(value1, value2);Applying the above query, To get the maximum value from two values. The query is as follows −Case 1We are giving both the values int.mysql> SELECT greatest(100, -300); After executing the above query, we will get the following output+--------------------+ | greatest(100, -300) | +--------------------+ | 100 | +--------------------+ 1 row in set (0.00 sec)Case 2We are giving both the ... Read More

How to modify the size of column in MySQL table?

George John
Updated on 24-Jun-2020 13:54:09

785 Views

We can modify a column size with the help of ALTER command. Let us see how to modify column size. Suppose we are defining any column with some size. At the time of inserting if we are giving more size in comparison to the one we defined, then an error will generate.The above problem can be reduced while modifying the size. For more understanding, we can create a table with the help of CREATE command −mysql> CREATE table ModifyColumnNameDemo -> ( -> id int, -> StudentName varchar(10) -> ); Query OK, 0 rows affected (0.45 sec)After creating a table successfully, ... Read More

Best way to test if a row exists in a MySQL table

Ankith Reddy
Updated on 06-Sep-2023 21:41:54

47K+ Views

To test whether a row exists in a MySQL table or not, use exists condition. The exists condition can be used with subquery. It returns true when row exists in the table, otherwise false is returned. True is represented in the form of 1 and false is represented as 0.For better understanding, firstly we will create a table with the help of CREATE command. The following is the query to create a table −mysql> CREATE table ExistsRowDemo -> ( -> ExistId int, -> Name varchar(100) -> ); Query OK, 0 rows affected (0.53 sec)After creating the table successfully, we will ... Read More

MySQL Error - #1046 - No database selected

Arjun Thakur
Updated on 24-Jun-2020 13:56:06

22K+ Views

The error-#1046 can occur when we are creating a table, but forget to select the database. Let us say we have started MySQL as shown below −After giving the correct password, the above window will open. Now create a table without choosing any database. This will show an error −mysql> CREATE table TblUni -> ( -> id int, -> Name varchar(100) -> );ERROR 1046 (3D000): No database selectedThe following screenshot is showing the same error −Now, choose any database to get rid of the above error. Firstly, let us check how many databases are present in MySQL with the help ... Read More

How to take backup of a single table in a MySQL database?

George John
Updated on 30-Jul-2019 22:30:23

640 Views

The backup of a table can be made with the help of backup table as well as mysqldump utility. The backup table concept was used in MySQL version 5.0 and its earlier version. Here, I am performing backup with the help of mysqldump. Firstly, we will open cmd with the help of shortcut key. The mysqldump will run at the cmd. Therefore, firstly open cmd with the help of shortcut key − windowskey+R; Here is the snapshot − Now, cmd will open − In this, the MySQL bin folder is present at the following location − ... Read More

N-ary Relationship in Database

Amit Diwan
Updated on 20-Jun-2020 09:52:14

13K+ Views

A relationship is an important part of any Entity relationship diagram as it shows the relation between two different entities. In an n - ary relationship, the n shows the number of entities in the relationship. It can be anything but the most popular relationships are unary, binary and ternary where the number of entities respectively are one, two and three.More information about Unary, Binary and Ternary relationships is as follows −Unary RelationshipWhen there is a relationship between two entities of the same type, it is known as a unary or recursive relationship. This means that the relationship is between ... Read More

Centralized Database Management System

Alex Onsman
Updated on 20-Jun-2020 09:53:33

20K+ Views

A centralized database is stored at a single location such as a mainframe computer. It is maintained and modified from that location only and usually accessed using an internet connection such as a LAN or WAN. The centralized database is used by organisations such as colleges, companies, banks etc.As can be seen from the above diagram, all the information for the organisation is stored in a single database. This database is known as the centralized database.AdvantagesSome advantages of Centralized Database Management System are −The data integrity is maximised as the whole database is stored at a single physical location. This ... Read More

Advertisements