Create is DDL command that is used to create the database, table, view etc in SQL.
Create database is very simple command that simply work to create new database in system that you can see by used SHOW command. If the database already exists, Error 1007 is returned.
mysql> CREATE Database new_database; Query OK, 1 row affected (0.00 sec) mysql> SHOW Databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | new_database | | test | +--------------------+ 6 rows in set (0.00 sec) mysql>
The keyword CREATE TABLE is followed by the name of the table that you want to create. Then within parenthesis, you write the column definition that consists of column name followed by its datatypes and optional constraints. There can be as many columns as you require. Each column definition is separated with a comma (,). All SQL statements should end with a semicolon (;).
mysql> CREATE Table staff( -> id tinyint unique, -> name char(30) not null, -> dob date, -> gender char(1) default 'T' -> ); Query OK, 0 rows affected (0.10 sec) mysql>
The VIEW is concept to present the data with selected data. It is as structure of user that data is select by other table. Is is a representation of table with struture change. It Create to use compand CREATE VIEW and it delete to use Drop view command. If you display the data of view you may be select view with select command.
mysql> CREATE View new_view AS -> SELECT id, name, contact FROM table_name; Query OK, 0 rows affected (0.04 sec) mysql> SELECT * FROM new_view; +------+--------+------------+ | ID | Name | Contact | +------+--------+------------+ | 1 | Ram | 9211420420 | +------+--------+------------+ 1 row in set (0.02 sec) mysql>
The above creates a user John123, able to connect with any hostname due to the % wildcard. The Password for the user is set to 'OpenSesame' which is hashed.
mysql> CREATE USER 'sqluser'@'%' IDENTIFIED BY 'password123'; Query OK, 0 rows affected (0.22 sec) mysql>