The following statement creates a new table named sales.visits to track the customer in-store visits: We will gradually introduce you to each individual options in the subsequent tutorials. Note that CREATE TABLE is complex and has more options than the syntax above. Fifth, a table may have some constraints specified in the table constraints section such as FOREIGN KEY, PRIMARY KEY, UNIQUE and CHECK.A column may have one or more column constraints such as NOT NULL and UNIQUE. Each column has an associated data type specified after its name in the statement. If the primary key consists of two or more columns, you need to specify the PRIMARY KEY constraint as a table constraint. If the primary key contains only one column, you can use the PRIMARY KEY keywords after the column name. Typically, you list the primary key columns first and then other columns. Fourth, each table should have a primary key which consists of one or more columns.Third, specify the name of the new table.Second, specify the schema to which the new table belongs.If you don’t specify it, the database_name defaults to the current database. The database_name must be the name of an existing database. First, specify the name of the database in which the table is created.CREATE TABLE table_name (Ĭode language: SQL (Structured Query Language) ( sql )
0 Comments
Leave a Reply. |