Create | DDL Commands in Create DDL Commands published on March 29, 2019 leave a reply CREATE Command Create command used to create new table in a database. Syntax : CREATE TABLE table_name (column1 datatype, column2 datatype, column3 datatype, column4 datatype, . . .) In CREATE command, there is two types of parameters : 1) Column - parameter specify the name of the column. 2) Datatype - parameters specify the type of data of column. Example : // CREATE Customer01 table CREATE TABLE Customer01 (Cust_Id int,Last_Name varchar(255), First_Name varchar(255),Address varchar(255),City varchar(255)); Above, example creates a table called "Customer01" that contains five columns: Cust_Id, Last_Name, First_Name, Address, and City. The Cust_Id column is of type int and will hold an integer. The Last_Name, First_Name, Address, and City columns are of type varchar and will hold characters, and the maximum length for these fields is 0-255 characters. Create New Table Using Another Existing (Old) Table We can create a copy of an existing table using CREATE command. The new table gets the same column definitions. We can use all columns or specific selected columns. If we create a new table using an old existing table, the new table will be filled with the existing values from old table. Syntax : CREATE TABLE new_table_name AS SELECT [* from] column1, column2, column3,... from existing_table_name [where]; In above syntax WHERE clause is optional. Examples : 1) CREATE TABLE Customer_Details AS SELECT Customer_Id,City FROM Customer01; 2) CREATE TABLE Customer_Details AS SELECT * FROM Customer01; 3) CREATE TABLE Customer_Details AS SELECT * FROM Customer01, Salary; 4) CREATE TABLE Customer_Details AS SELECT * FROM Customer01, Salary WHERE Customer_name="Raj" AND Salary_Month="June"; In above examples, We can select particular column. We can use also * FROM to copy all table columns. We can also select multiple tables. In third and fourth example i am using two different tables Customer01 and Salary. * * * * * * * * * * * * * * * In Easy Language (Simplify) CREATE command used to create new table from existing database. Using with CREATE command also we can create database. Tweet Share Share Share Previous Post DROP | DDL Commands | Drop Command In SQL Next Post DDL Commands | Data Definition Language | SQL Commands post written by: Anonymous Related PostsTRUNCATE | DDL Command | TRUNCATE SQL TRUNCATE Command Truncate command used to delete data from table, but not the table structure. This command may delete who… Continue ReadingSQL Commands | DDL, DML, TCL, DCL, DQL SQL Commands: SQL Command !-- Image Credit :- Gfycat -- SQL commands are guidelines, coded into SQL proc… Continue ReadingDROP | DDL Commands | Drop Command In SQL DROP Command SQL Drop command used to remove a table definition and all the data, indexes, triggers, constraints and permission… Continue ReadingALTER | DDL Command | Alter Command In SQL ALTER Command Alter command used to add, modify and delete columns and constraints in an existing table. ALTER TABLE | ALTE… Continue Reading
0 Comments: