OpenSource For You

Creating a database in MariaDB

-

When entering the account administra­tor password set up during installati­on, you will be given a MariaDB prompt.

Create a database on students by using the following command:

CREATE DATABASE students;

Switch to the new database using the following command (this is to make sure that you are currently working on this database):

USE students;

Now that the database has been created, create a table: CREATE TABLE details (student_id int(5) NOT NULL AUTO_ INCREMENT, name varchar(20) DEFAULT NULL, age int(3) DEFAULT NULL, marks int(5) DEFAULT NULL, PRIMARY KEY(student_i)d );

To see what we have done, use the following command:

show columns in details;

Each column in the table creation command is separated by a comma and is in the following format: Column_Name Data_Type[(size_of_data)] [NULL or NOT NULL] [DEFAULT default_value] [AUTO_INCREMENT] These columns can be defined as: Column Name: Describes the attribute being assigned. Data Type: Specifies the type of data in the column. Null: Defines whether null is a valid value for that field –it can be ‘null’or ‘not null’. Default Value: Sets the initial value of all newly created records that do not specify a value. auto_increment: MySQL will handle the sequential numbering of any column marked with this option, internally, in order to provide a unique value for each record. Ultimately, before closing the table definition, we need to use the primary key by typing PRIMARY KEY( column name). It guarantees that this column will serve as a unique field.

 ??  ?? Figure 3: A sample table created
Figure 3: A sample table created

Newspapers in English

Newspapers from India